Part Number: LAUNCHXL-F28069M
Other Parts Discussed in Thread: MOTORWARE
Hello all,
I've been trying to get i2C communications working with the above mentioned uC in the Motorware Instaspin labs.
I managed to find I2C drivers online and I thought I had a the ability to write data figured out. Unfortunately, the success was mixed. Sometimes I couldn't get any output on the I2C lines at all, other times it worked, and oddly sometimes the bits in the slave and data bytes would all be shifted to the right by one. After making various changes I can longer even get that. The I2C lines just stay high.
I believe the setup code is working as expected and that the issue is in my write function. If I comment it out the device no longer hangs in the "Idle" state and the motor run as normal. When looking at the registers (they don't change), the I2CSTR is 0x0420, and the MDR register is 0x0220. The only thing i can think of worth noting in this is that the SCD bit is set.
I'll include all of the files I changed (hal, i2c, etc.) just in case it helps. I2CCode.zip
Here is the write function as I believe it is the culprit:
void accel_Write(HAL_Handle halHandle, uint16_t register_add, uint16_t data ){
while(I2C_isMasterBusy(halHandle->i2cHandle));
I2C_clearStopConditionDetection(halHandle->i2cHandle);
while(I2C_isMasterStopBitSet(halHandle->i2cHandle));
while(!((I2C_getStatus(halHandle->i2cHandle) & (I2C_I2CSTR_XRDY_BITS | I2C_I2CSTR_ARDY_BITS))));
// If a NACK occurred, SCL is held low and STP bit cleared
if ( I2C_isNoAck(halHandle->i2cHandle) )
{
I2C_setMasterStopBit(halHandle->i2cHandle); // send STP to end transfer
I2C_clearNoAckBit(halHandle->i2cHandle); // clear NACK bit
}
I2C_putData(halHandle->i2cHandle, register_add);
I2C_MasterControl(halHandle->i2cHandle, I2C_Control_Single_TX, 0, 2);
//while(I2C_isMasterBusy(halHandle->i2cHandle));
// while(!((I2C_getStatus(halHandle->i2cHandle) & (I2C_I2CSTR_XRDY_BITS | I2C_I2CSTR_ARDY_BITS))));
// // If a NACK occurred, SCL is held low and STP bit cleared
// if ( I2C_isNoAck(halHandle->i2cHandle) )
// {
// I2C_setMasterStopBit(halHandle->i2cHandle); // send STP to end transfer
// I2C_clearNoAckBit(halHandle->i2cHandle); // clear NACK bit
// }
// I2C_putData(halHandle->i2cHandle, register_add);
while(!((I2C_getStatus(halHandle->i2cHandle) & (I2C_I2CSTR_XRDY_BITS | I2C_I2CSTR_ARDY_BITS))));
// If a NACK occurred, SCL is held low and STP bit cleared
if ( I2C_isNoAck(halHandle->i2cHandle) )
{
I2C_setMasterStopBit(halHandle->i2cHandle); // send STP to end transfer
I2C_clearNoAckBit(halHandle->i2cHandle); // clear NACK bit
}
I2C_putData(halHandle->i2cHandle, data);
while(!((I2C_getStatus(halHandle->i2cHandle) & (I2C_I2CSTR_XRDY_BITS | I2C_I2CSTR_ARDY_BITS))));
// If a NACK occurred, SCL is held low and STP bit cleared
if ( I2C_isNoAck(halHandle->i2cHandle) )
{
I2C_setMasterStopBit(halHandle->i2cHandle); // send STP to end transfer
I2C_clearNoAckBit(halHandle->i2cHandle); // clear NACK bit
}
while(!I2C_isStopConditionDetected(halHandle->i2cHandle));
} // end of accel_Write() function
The while loops are there as the make sure data is loaded into the output shift register when it is ready and to handle NACKS.
I'd appreciate any help in trying to get this to work.
Thanks,
Joshua Russell