Hello!
I was trying to switch to the USCI_B I2C Driverlib and i noticed i couldn't reproduce a clean repeated start condition (e.g. for reading a byte from the slave). If i watch the waveforms with the oscilloscope i can see the SDA line rising and falling without even reaching 3V3 level. maybe it's enough for the i2c slave i'm using (it works, i receive the right bytes) but I'm trying to figure out if this represents a potential error cause or not.
Here are the snippets (with and without driverlib):
// Test RGB (manuf. ID = 0xE0)
USCI_B_I2C_setSlaveAddress(USCI_B0_BASE, RGBFR_ADDR);
if(USCI_B_I2C_masterSendSingleByteWithTimeout(USCI_B0_BASE, MANUFACTURER_ID, 20000))
{
if(USCI_B_I2C_masterReceiveSingleStartWithTimeout(USCI_B0_BASE, 20000))
{
receivedMsg = USCI_B_I2C_masterReceiveSingle(USCI_B0_BASE);
}
}
if(receivedMsg==0xE0) peripherals |= RGB_FRECCE;
receivedMsg=0;
here is the function i made without driverlib, called as "I2C_Receive_Single_Byte(RGBFR_ADDR, MANUFACTURER_ID)
char I2C_Receive_Single_Byte(char Slave_Address, char RegAddr)
{
char received_data=0x00;
UCB0I2CSA = Slave_Address; // Address Assignment
UCB0IFG &=~ UCTXIFG; // Flag Clear
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
while(!(UCB0IFG&UCTXIFG)); // While Flag=0 (UCTXIFG=1 when START is generated, data can be written)
UCB0IFG &=~ UCTXIFG; // Flag Clear
UCB0TXBUF = RegAddr; // Data (register to read) load
while((UCB0CTL1&UCTXSTT)) // While start not ack'ed
{
if(UCB0IFG&UCNACKIFG) // if NACK, issue stop and exit
{
UCB0IFG &=~ UCNACKIFG;
UCB0CTL1 |= UCTXSTP;
return 1;
}
}
UCB0CTL1 &=~ UCTR; // Prepare to receive
UCB0IFG &=~ (UCTXIFG+UCRXIFG); // Flag Clear
UCB0CTL1 |= UCTXSTT; // Issue repeated start
while(UCB0CTL1&UCTXSTT) // While start not ack'ed
{
if(UCB0IFG&UCNACKIFG) // if NACK, issue stop and exit
{
UCB0CTL1 |= UCTXSTP;
return 1;
}
}
UCB0CTL1 |= UCTXSTP;
while(!(UCB0IFG&UCRXIFG)); // While a byte is not received
received_data = UCB0RXBUF; // Read and save
__delay_cycles(10000);
return received_data; // Self descripting
}
should i introduce some kind of extra polling in the driverlib? Am i worrying for nothing?
Thank you!