I2C sensor on USART2 Serial communication not working

2 visualizaciones (últimos 30 días)
Sanath
Sanath el 13 de Sept. de 2023
Comentada: Sanath el 28 de Sept. de 2023
Hello,
I am using the embedded coder support package in simulink to interface with my onboard MEMS acceleration sensor (LSM303AGR) on my STM32F411VET discovery board. I could successfully connect and run simple LED program through USART2 on simulink block and it returns button state values as well on display, while running in external mode.
I am moving on to more complicated communication, where i am accessing the I2C sensor via USART2 but I am not able to establish a communication. I have I2C read and I2C write blocks inside the embedded coder package which i am using along with correct read and write addresses for the sensor.
However, My I2C sensor will not respond over USART2, is there a step which I am missing?
How does one transmit and receive I2C sensor data over USART2 serial communication?
Your help would be appreciated.

Respuestas (2)

Vikky Patil
Vikky Patil el 14 de Sept. de 2023
Editada: Vikky Patil el 14 de Sept. de 2023
Hello Sanath,
We assume you want to read the data from the sensor in Simulink using external mode. The sensor is connected via an I2C interface with the controller. The interface used for external mode is serial.
We don’t have an exact example on the same hardware, but you can refer to an example shipped in 23b demonstrating reading sensor data(which is connected via an I2C interface with the controller) and sending the results over CAN to another controller.
Note : The sensor in the example is to read humidity and temperature.
You can refer to the example for understanding how to read the data using the I2C block and instead of sending it over CAN using CAN write a block you can connect it to an output port and run the model in external mode.
if issue persist, please contact technical support: Contact Us - MATLAB & Simulink (mathworks.com)

Sanath
Sanath el 15 de Sept. de 2023
@Vikky Patil based on two examples, one for I2C communication and another about the specific sensor, LSM303AGR, I made a simulink model, but it does not return any value. what do you think could be the issue?
  8 comentarios
Vikky Patil
Vikky Patil el 21 de Sept. de 2023
It depends upon the rate at which you are logging and number of data bytes getting logged. If you are seeing data drops in external mode use external FTDI and try to increase the baud rate to its max.
Sanath
Sanath el 28 de Sept. de 2023
@Vikky Patil Thank you so much for all your help. My model is finally working with all values for x,y and z axis. Your suggestion and explainations really helped me move forward.

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by