TCA9548A I2C multiplexer interface with nRF52832 DK

I was able to interface a 9 axis MPU9250 sensor with nRF52832 via TWI. Now I want to read more number of sensor's data i.e., I want to read 8 IMU sensors data. Since, nRF52832 has only 2 TWI ports, I have interfaced all the sensors via a I2C multiplexer i.e., TCA 9548A. When I am initializing the i2c multiplexer using its address 0x70, the flow is struck inside the while (m_xfer_done == false){} only. m_xfer_done state is not becoming true at any time. Is it because of the error handling function? if so how to debug the error handling function? Please throw me some answer soon.

Thanks 

Parents
  • Hello,

    Where is it you are using the while (m_xfer_done == false){}? Is it inside an interrupt? A common reason to be stuck like this is because you are waiting inside an interrupt, and although the new interrupt that is supposed to set m_xfer_done = true; actually happened, it doesn't get access to the CPU because the CPU is already handling another interrupt with the same or higher priority (typically the same, if you are waiting inside another TWI/I2C interrupt. 

    So you need to return from the interrupt, and hanlde the waiting somewhere else.

    Check out this piece of pseudo code:

    bool m_xfer_done = false;
    
    
    void twi_interrupt_handler(buffer)
    {
        m_xfer_done = true;
    }
    
    void timer_callback_handler(void)
    {
        twi_send_data(...);
        while (m_xfer_done == false)
        {
            // Wait.
        }
        twi_send_data(...);
        ...
    }
    
    main()
    {
        init_twi(twi_interrupt_handler); // twi_interrupt is the callback.
        timer_start(timer_callback_handler); // same priority as TWI callback
    }

    In this case, the m_xfer_done will never be true, because the CPU is already running in an interrupt priority equal to the TWI interrupt, so the twi_interrupt_handler will be blocked.

    Is this the case? If so, perhaps you can explain what you want to do, and we can think of some way to make it work.

    Best regards,

    Edvin

  • I would like to know, what is the process of verifying a device's i2c address. can I use  "nrf_drv_twi_tx(&m_twi, mux_address, valuebuffer, 1,true)" this function to send the device address?

    Here, mux_address is the address of the slave device i.e., 0x70 and valuebuffer[2] contains the the register address and the value to written is 1u.

  • How this Multiplexer in particular works, I don't know. You would have to ask the manufacturer of that device. Does the multiplexer respond to several addresses, or does it only have one address, and the second byte of the payload buffer (valuebuffer) decides what device to forward the data to? What multiplexer do you use? Does it have a datasheet?

    BR,

    Edvin

  • Hello Edvin,TCA9548A is the i2c multiplexer I am using. The problem statement is as follows:

    The I2C multiplexer is connected to nRF52832 via twi communication. I2C multiplexer is 1 to 8 channel i2c multiplexer which selects each of the 8 channels at a time. 8 IMU sensors(MPU9250) are connected to each of the 8 channels. At a time a single IMU sensor reading has to be done, then the control goes to the net IMU sensor and so on upto 8 IMU sensors. I was able to write the driver code for the IMU sensor and I am able to read the readings of the single IMU sensor.

    Coming to I2C multiplexer, every time one channel has to be selected and corresponding connected IMU sensor has to be read. My question is how to select each channel every time. The datasheet of the I2C multiplexer (tca9548a) has been attached herewith. 

    Once we select the channel how to stall the control to that channel only? How will I send the MPU9250 address and reading commands via i2c multiplexer?

    I2C_multiplexer_tca9548a.pdf

  • Hello,

    I am sorry, but these questions are not related to the nRF52832 or our SW. I am not familiar with the device, and I don't have one to test with, so while I could read through the data sheet and make some suggestions, I have no idea whether it would work. 

    I suggest you study the pages 16-22 closely, as they look relevant for your questions. But if that doesn't help, you need to contact Texas Instruments for further instructions on how to use their device. 

    BR,
    Edvin

  • HI,

    I understood the context. I will let you know the steps need to be followed, please explain me about the relevant programming functions of the nrf52 to perform these steps:

    1. first step is to check whether the device with address 0x70 is connected to the microcontrller

    2. One control register of the above mentioned device is to be enabled by writing 0x01 into it to select first channel

    3. The control register has to be changed to 0x20 to select the next channel

    4. Next, the control register address has to changed to 0x40 to select the next channel and so on.

  • So the control register is part of the TWI payload, right? You said in your initial post that you already succeeded in interfacing one MPU (I assume that was without the I2C multiplexer), so you have the basic I2C up and running, right? Did you try to modify that application to communicate with the I2C Multiplexer instead of the MPU directly?

    BR,

    Edvin

Reply Children
No Data
Related