I am currently trying to control Arduino Uno with STM32L47RG in Simulink via UART. But I think Arduino Uno isn't receiving any of the data. The STM32's Rx and Tx pins are connected to the Arduino Uno's Rx and Tx.
The Arduino code I wrote is referenced from the Arduino Cookbook , the Serial Input Basics, and this example.
I have used an oscilloscope to check whether it is sending the data, and there is data being sent as shown in the image below. Can anyone help identify where I got wrong?
Simulink model:
Oscilloscope (sending the number 2 through UART):
Arduino Code:
/*
* SerialReceive sketch
* Blink the LED at a rate proportional to the received digit value
*/
const int ledPin = 13; // pin the LED is connected to
int blinkRate=0; // blink rate stored in this variable
void setup()
{
Serial.begin(115200); // Initialize serial port to send and receive at 9600 baud
pinMode(ledPin, OUTPUT); // set this pin as output
}
void loop()
{
if ( Serial.available()) // Check to see if at least one character is available
{
char ch = Serial.read();
if(ch >= '0' && ch <= '9') // is this an ascii digit between 0 and 9?
{
blinkRate = (ch - '0'); // ASCII value converted to numeric value
blinkRate = blinkRate * 100; // actual blinkrate is 100 mS times received digit
}
}
blink();
}
// blink the LED with the on and off times determined by blinkRate
void blink()
{
digitalWrite(ledPin,HIGH);
delay(blinkRate); // delay depends on blinkrate value
digitalWrite(ledPin,LOW);
delay(blinkRate);
}