Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

TMS320F28069M: I2C master - how to terminate the transmission (ex. if the transfer takes too long)?

$
0
0

Part Number:TMS320F28069M

Hi,

I have finally implemented the I2C driver, however I would like to have a time-out control in case the transfer takes too long.

I post my current code below. I want to simply let go off transmission and release the bus in case the XRDY register is not ready for too long time. I've tried to reset the module and it works OK from the hardware perspective (the bus is simply released), but the software doesn't send the STOP condition - and thus cannot transmit the next byte (STP bit of I2CMDR is not ready). How can I force the stop condtition?

I2C_Error_e I2C_writeData(I2C_Handle i2cHandle, int16_t address, uint16_t data[], uint16_t bytesToSend_no)
{
    static int16_t iByte, cntTimeout = 0;

    // Check if the bus is not waiting for STOP condition
    if (i2cHandle->I2CMDR.bit.STP == 1)
    {
       return I2C_Error_StpNotReady;
    }

    // Check if bus busy
    if (i2cHandle->I2CSTR.bit.BB == 1)
    {
       return I2C_Error_BusBusy;
    }

    // Setup slave address
    I2C_setSlaveAddress(i2cHandle, address);

    // Setup number of bytes to send
    I2C_setDataBytesNumber(i2cHandle, bytesToSend_no);

    // Set the master-mode as it is switched to slave automatically after generating a STOP condition
    I2C_setMode(i2cHandle, I2C_Mode_Master_Transmitter);

    // Prepare stop condition to be sent after transmition ends
    I2C_stop(i2cHandle);

    // Send start condition
    I2C_start(i2cHandle);

    for(iByte = 0; iByte<bytesToSend_no; iByte++)
    {
//Do nothing till bus is free while( i2cHandle->I2CSTR.bit.XRDY == 0 ) { if(cntTimeout++ > 1000) // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< RELEASE THE BUS HERE { I2C_reset(i2cHandle); I2C_enable(i2cHandle); return I2C_Error_TimeOut; } }; // Send data to the transmit register i2cHandle->I2CDXR = data[iByte]; } return I2C_Error_NoError; }


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>