Page 1 of 2

Wait Serial1 transmission to complete CODE

Posted: Fri May 01, 2020 10:54 pm
by cpt_cyp
Hi

I am using rs485 protocol to communicate other modules on Arduino Mega.
But STM32F103 (bluepill+bootloader), i cant send any serial1 message. i am getting messages well.
This is my Arduino Mega working code:

Code: Select all

digitalWrite(enablePin, HIGH);     //high signal to send data
 Serial1.println("message"); //message
    while (!(UCSR1A & (1 << UDRE1)))  // Wait for empty transmit buffer
    UCSR1A |= 1 << TXC1;  // mark transmission not complete
    while (!(UCSR1A & (1 << TXC1)));   // Wait for the transmission to complete
digitalWrite(enablePin, LOW);     //data send
I cant compile this section is giving me error:

Code: Select all

 while (!(UCSR1A & (1 << UDRE1)))  // Wait for empty transmit buffer
 UCSR1A |= 1 << TXC1;  // mark transmission not complete
 while (!(UCSR1A & (1 << TXC1)));   // Wait for the transmission to complete
how can i deal ??

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 4:53 am
by fpiSTM
Those definitions are not part of STM32.
They are for AVR.
Try using

Code: Select all

 Serial.flush();

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 11:32 am
by cpt_cyp
I tried but not working and also code stucked on Serial1.flush();

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 12:18 pm
by stas2z
it's working and shouldn't stuck

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 12:32 pm
by fpiSTM
Well, if it's not work then share your full sketch and also all relevant info: stm32 core used, ide version, ....

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 1:04 pm
by cpt_cyp
---------------

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 1:15 pm
by fpiSTM
Ok. Thanks.
So you used libmaple core and I don't know if flush is implemented.
I move this to the libmaple core subforum

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 1:21 pm
by stas2z
@fpiSTM it's implemented in libmaple/roger's core and do the same, at least last time ive tried it with rs485 using roger's core

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 1:34 pm
by fpiSTM
I thouh it was ;)

Re: Wait Serial1 transmission to complete CODE

Posted: Sat May 02, 2020 1:44 pm
by cpt_cyp
so if two cores are same why serial.flush command stuck.
i didnt try any other cores.
and also tried delaymicrosecond but no way..