I2C ROM drivers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C ROM drivers

469 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketdawg on Mon Nov 18 17:51:24 MST 2013
I2C_PARAM_t

there is no documentation regarding the correct values to place in num_bytes_send and num_bytes_rec

I need to send
    address, command, data0, data1
and send/receive
   address, command, (address w/read) receive data0, data1

I do not know if the num_bytes_send should include the address byte or not, looks like it should via LPCOpen sample with i2c_master_transmit
but the same sample shows that a read does not include the address when doing a i2c_master_receive

a bit confusing given no documentation.

Labels (1)
0 Kudos
1 Reply

341 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketdawg on Tue Nov 19 10:04:18 MST 2013
OK, I figured out that num_bytes_send and num_bytes_rec must include the address byte.
But here is a strange one.
If I use the API i2c_master_transmit_intr() it works as expected.
but if I use the API i2c_master_tx_rx_poll()

I get a strange attempt to read after sending, even though the receive buffer and bytes are 0.
This gives a false ERR_I2C_NAK
as seen in the capture
makes me think the polling function is borked.

ErrorCode_t writeRegister(registers_t which, uint8_t *buffer)
{
uint8_t SendData[4];
I2C_PARAM_T param;

SendData[0] = address & 0xFE; // make sure bit 0 is 0
SendData[1] = (uint8_t)which;
SendData[2] = *buffer++;
SendData[3] = *buffer;

param.num_bytes_send    = 4;
param.buffer_ptr_send   = SendData;
param.num_bytes_rec     = 0;
param.buffer_ptr_rec    = 0;
param.stop_flag         = 1;
param.func_pt           = cbI2CComplete;
/* Set timeout (much) greater than the transfer length */
gErrorCode = -1;
LPC_I2CD_API->i2c_set_timeout(i2cHandleMaster, 100000);
LPC_I2CD_API->i2c_master_transmit_intr(i2cHandleMaster, &param, &result);
//gErrorCode = LPC_I2CD_API->i2c_master_tx_rx_poll(i2cHandleMaster, &param, &result);
while (gErrorCode == -1)
{
__WFI();
}
if(gErrorCode != LPC_OK)
DEBUGOUT("i2c_master_receive error code : %x\r\b", gErrorCode);
return gErrorCode;
}

0 Kudos