This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F2800157: Switching Master to Slave

Part Number: TMS320F2800157


Tool/software:

Hi Team,

I am using two Boards (TMS320F2800157) connected through I2C, I am trying to use FIFO to send and receive data.

I was able to send data from 1st board TX Buffer to 2nd Board RX Buffer and raise interrupt in the 2nd Board itself.

Inside the buffer I was able to getData. Inside the same ISR I cleared all interrupts and then tried to putData so that I can receive in 1st Board RX Buffer with a raised ISR call.

I saw in 2nd board that while sending, the bus was busy and MST or master mode bit was turned into 0 as well as arbitration lost bit was set high.

My guess is that the 1st Board is master and not releasing control for other to send data.

How can I release the master control on 1st board as soon as transaction is done for the first time if my above guess is write?

Thanks!

  • With reference to this here is configuration

    1st and 2nd board running same code base.

    Both configured as Controller_Send_Mode, FIFO interrupt raised for 1 byte receive only, Both devices will its own address.

    From 1st board the ISR for FIFO is called once which is received by the same ISR function on 2nd board, then in the same ISR code for sending back data is written, which should raise ISR in the first board for receiving.

    pseudo code for ISR running on both boards

    FIFO_ISR () {

    //Code for receiving data will only be called in 2nd board if some data is received in RXFF buffer. In 1st board as this ISR is called manually this if clause will not run.

    if ((I2C_getInterruptStatus(I2C_BASE) & I2C_INT_RXFF) != 0){
            rData =
                            I2C_getData(I2C_BASE);
        }

    //Code for sending data which will run once this ISR function is called manually in 1st board and once in 2nd board when this ISR is raised due to receiving data  (RXFF)
        I2C_putData(
                            I2C_BASE,
                            sData;
        I2C_sendStartCondition(I2C_BASE);
        SysCtl_delay(50);
        I2C_sendStopCondition(I2C_BASE);
       
        I2C_clearInterruptStatus(I2C_BASE, I2C_INT_RXFF | I2C_INT_TXFF);
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP8);

    }

    In 1st board I was not getting ISR raised for getting received data from 2nd board.

    But data transmission from 1st to 2nd is working fine.

    Configuration done for both devices pseducode

    I2C_disableModule(I2C_BASE);
        I2C_initController(I2C_BASE, DEVICE_SYSCLK_FREQ, 400000,
                           I2C_DUTYCYCLE_50);
        I2C_setConfig(I2C_BASE, I2C_CONTROLLER_SEND_MODE);
        I2C_setDataCount(I2C_BASE, 1);
        I2C_setBitCount(I2C_BASE, I2C_BITCOUNT_8);
        switch (some value)
        {
        case some value:
            I2C_setOwnAddress(I2C_BASE, 1st address);
            I2C_setTargetAddress(I2C_BASE, 2nd address);
            break;
        case some value:
            I2C_setOwnAddress(I2C_BASE, 2nd address);
            I2C_setTargetAddress(I2C_BASE, 1st address);
            break;
        }
        I2C_setEmulationMode(I2C_BASE, I2C_EMULATION_STOP_SCL_LOW);
        I2C_enableFIFO(I2C_BASE);
        I2C_setFIFOInterruptLevel(I2C_BASE, I2C_FIFO_TX1, I2C_FIFO_RX1);
        I2C_enableInterrupt(I2C_BASE, I2C_INT_RXFF | I2C_INT_STOP_CONDITION);
        I2C_clearInterruptStatus(I2C_BASE, I2C_INT_TXFF | I2C_INT_RXFF);
        I2C_disableLoopback(I2C_BASE);
        I2C_enableModule(I2C_BASE);

  • Hi Kaustuv,

    As you've correctly identified, one board needs to release control of being the controller in order for the other board to act as the controller. In other words, even though there can be multiple targets, there can only be one controller in an I2C system. However, an I2C module can start off as a controller and become a target and vice versa in certain cases during operation (specially in interrupt handlers in this case). Refer to the I2C section as a whole specifically Table 19-2 Operating Modes of I2C Module.

    Best Regards,

  • Hi Aishwarya,

    I am trying the same using above code describe,

    Can you please suggest me changes on my existing code for better understanding.

    Regards,

    Kaustuv

  • Inside the ISR itself after receiving how can I switch to the other mode for receiving. Should I use Controller or Target receiver. What else is needed to be done before switching? Please use the sample code above for explanation!

    Regards,

    Kaustuv

  • Kaustuv,

    Have you looked at the table I referred to earlier (linked here)? Like I already mentioned, you cannot have two controllers in a system. There has to be a controller and a target. According to your code, you have two controllers sending data. Use i2c_ex3_external_loopback example as a reference as well.

    Best Regards,

    Aishwarya

  • Hi, Aishwarya

    Thanks for the above document, earlier I was following some other document which was not enough.

    From the new document I got to understand that if two TMS320F2800157 are connected with SDA, SCLK and if they want to communicate as master slave using FIFO register then the :-

    1st Board - Controller Send Mode

    2nd Board - Target Receiver Mode

    Switch the configuration in runtime

    1st Board - Controller Receive Mode

    2nd Board - Target Send Mode

    Note this system is not using any EEPROM.

    If my understanding is correct considering the above configuration then can you provide me suitable example where 1 byte of data is transferred from Controller to Target and vice versa. The examples which comes with C2000 is not sufficient or not self explanatory and some examples confuses a lot.

    Related to the above scenario and configuration can you kindly give another example of transferring only 1 byte of data from Transmitter (TMS320) to Controller (TMS320) board where Controller is initiated with Controller Receive Mode and Target in Target Send Mode. No data will be transferred from Controller to Target but Controller will always ask target to send data.

    Regards

    Kaustuv

  • Kaustuv,

    If my understanding is correct considering the above configuration then can you provide me suitable example where 1 byte of data is transferred from Controller to Target and vice versa. The examples which comes with C2000 is not sufficient or not self explanatory and some examples confuses a lot.

    Related to the above scenario and configuration can you kindly give another example of transferring only 1 byte of data from Transmitter (TMS320) to Controller (TMS320) board where Controller is initiated with Controller Receive Mode and Target in Target Send Mode. No data will be transferred from Controller to Target but Controller will always ask target to send data.

    Understanding is correct. Along with TRM documentation, refer to i2c_ex3_external_loopback.c and i2c_ex5_controller_target_interrupt as a basis for how to configure those requirements. We currently do not have examples that do exactly what you've described here. I've made a note of your request and feedback and will discuss with the team. If you have any specific questions regarding the examples or your test case, let me know.

    Best Regards,

    Aishwarya

  • Aishwarya,

    Is it possible to start a controller as receiver and target as sender from initial stage and never switch to controller as sender and a target as receiver. From the flow chart given in the document shared I got to understand that it is possible to init the boards directly controller as receiver and a target as sender.

    Is my understanding is correct then what steps I need follow to transmit data?

  • Kaustuv,

    Yes, your understanding is correct. As you've identified, you can follow the flow chart for this. 

    Best Regards,

    Aishwarya

  • Hi Aishwarya,

    What we discussed before is working absolutely fine. Now for our last step of the module development we need your suggestion.

    Completed:

    1. Configuring Master as Controller Receive Mode using FIFO

    2. Configuring Slave as Target Send Mode using FIFO.

    3. Provided some data (putData()) in Slave TX FIFO register.

    3. Initialed Fetch Data through Master.

    4. Received Data in Master RX FIFO from slave TX FIFO.

    Last Step we need to complete:

    1. As master is running asynchronously so it initiate call for transferring data non periodically.

    2. On slave I need some mechanism like interrupts to intimidate that the TX FIFO register data of Slave is already transferred to Master and new data should be written on the same TX FIFO register so that next time or cycle master can get the new updated data.

    Note: We are not changing any Configuration of Master using setConfig() between two consecutive Initiate calls for transferring data.  

    We will be waiting for your suggestion!

    Thanks

    Regards,

    Kaustuv

  • Kaustuv,

    Glad to hear it. As I'm sure you know we do not have code for this specific use case, but here are my thoughts.The I2C TRM chapter / I2C registers descriptions discuss how I2C hardware can trigger interrupts after a certain amount of data has been sent / received (TX/RX FIFO interrupts). In these interrupts, you can perform whatever action is needed. This should be helpful for question #2. As I cannot suggest exactly what to do, the best action here would be to refer to other E2E threads and debug your program until it does what is required Slight smile 

    Best Regards,

    Aishwarya