Hi,
I have a Netburner Mod5282. How do I use the i2CReadBuf and i2CSendBuf routines with the CX24116 chip? Basically, The I CX24116 has 256 registers, and I need to be able to read and write to one or more registers on the device.
I am using Multi-master mode, and I understand that I need to call i2CInit with a slave address and frequency divider. After that, here's the prototype for I2CReadBuf:
BYTE I2CReadBuf( BYTE addr, PBYTE buf, int num, bool stop = true );
addr BYTE The 7-bit address you wish to read the buffer from.
buf PBYTE A pointer to the BYTE buffer you wish to read to.
num int The number of bytes to read.
stop bool If true (default): Terminate communication with stop. If false: Do not terminate transmission. (This is useful if the user wishes to send a restart instead of a stop.)
There are one too few parameters for this to work. It's my understanding I need to send out both the device address for the CX24116 (0x55) and send out an address for which register I want to read. There's only one address parameter listed here. Which address is the "addr" parameter referring to? The device address or the register address on the device? How do I send the other address? Please clear up this confusion.
Thanks,
Dan
i2CReadBuf trouble
Re: i2CReadBuf trouble
Hi,
There is no standard for addressing registers in I2C devices so you will have to look through the data sheet for the CX24116. In most cases I have seen you will be required to first send an address and then do an I2C restart and then read the data. Look at how GetTime_NXPPCF8563 reads data from the NXP real time clock in rtc.cpp.
The NXP RTC has an address of 0x51. First we fill RTCdata with the address of the register we want to read from... in this case we want to start reading from register 0x2. We then send that register number to the RTC and check for an error. If no error we send a restart on the bus to switch from writing to reading. We then read 7 bytes of data, which should be registers 2-9 of the RTC.
RTCdata[0] = 0x2;
if( I2CSendBuf( 0x51, RTCdata, 1, FALSE ) != I2C_MASTER_OK)
return 1;
if( I2CRestart( 0x51, TRUE ) != I2C_NEXT_READ_OK ) // Restart for read
return 1;
if( I2CReadBuf( 0x51, RTCdata, 7 ) != I2C_OK )
return 1;
-Larry
There is no standard for addressing registers in I2C devices so you will have to look through the data sheet for the CX24116. In most cases I have seen you will be required to first send an address and then do an I2C restart and then read the data. Look at how GetTime_NXPPCF8563 reads data from the NXP real time clock in rtc.cpp.
The NXP RTC has an address of 0x51. First we fill RTCdata with the address of the register we want to read from... in this case we want to start reading from register 0x2. We then send that register number to the RTC and check for an error. If no error we send a restart on the bus to switch from writing to reading. We then read 7 bytes of data, which should be registers 2-9 of the RTC.
RTCdata[0] = 0x2;
if( I2CSendBuf( 0x51, RTCdata, 1, FALSE ) != I2C_MASTER_OK)
return 1;
if( I2CRestart( 0x51, TRUE ) != I2C_NEXT_READ_OK ) // Restart for read
return 1;
if( I2CReadBuf( 0x51, RTCdata, 7 ) != I2C_OK )
return 1;
-Larry