Wait Serial1 transmission to complete CODE
-
- Posts: 505
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: Wait Serial1 transmission to complete CODE
Can you please a simple project which shows the problem?
Your code is too complex to find the error.
Your code is too complex to find the error.
Re: Wait Serial1 transmission to complete CODE
i did a project on arduino mega which they are communicate with other boards on rs485.
i have one arduino mega which is connected to pc via ethernet. its getting some variables and delivering other modules via rs485.
i used stm32f103 (bluepill) and getting messages well. but it cant send messages on rs485
if you read my prev. posts i did serial.flush() command but code stuck there.
i have one arduino mega which is connected to pc via ethernet. its getting some variables and delivering other modules via rs485.
i used stm32f103 (bluepill) and getting messages well. but it cant send messages on rs485
if you read my prev. posts i did serial.flush() command but code stuck there.
Re: Wait Serial1 transmission to complete CODE
i tried serial.flush is working
but serial1.flush not working
code stuck and i cant upload new code from ide until unplug connection (turn off the board power)
but serial1.flush not working
code stuck and i cant upload new code from ide until unplug connection (turn off the board power)
-
- Posts: 505
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: Wait Serial1 transmission to complete CODE
As I wrote, please post a simple sketch which shows the problem case.
Re: Wait Serial1 transmission to complete CODE
the flush codes looks like this
https://github.com/rogerclarkmelbourne/ ... l.cpp#L139
if you have a setup something like eclipse or vscode done appropriately, they would be able to make a reference jump to the code.
i'd suggest pick up some skills with a st-link and play with debug, it is kind of fun for someone learning it for a first time, there is a learning curve there but it is well worth it
another thing to try, try writing some data
before doing a flush, at least try to narrow down the problem. libmaple core is a 'community core' so it'd pretty much be like you have downloaded public domain codes and u'd need to try to figure things out as well.
https://github.com/rogerclarkmelbourne/ ... l.cpp#L139
Code: Select all
/* edogaldo: Waits for the transmission of outgoing serial data to complete (Arduino 1.0 api specs) */
void HardwareSerial::flush(void) {
while(!rb_is_empty(this->usart_device->wb)); // wait for TX buffer empty
while(!((this->usart_device->regs->SR) & (1<<USART_SR_TC_BIT))); // wait for TC (Transmission Complete) flag set
}
i'd suggest pick up some skills with a st-link and play with debug, it is kind of fun for someone learning it for a first time, there is a learning curve there but it is well worth it
another thing to try, try writing some data
Code: Select all
Serial1.write(0x00)
Last edited by ag123 on Sat May 02, 2020 4:33 pm, edited 3 times in total.
-
- Posts: 505
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: Wait Serial1 transmission to complete CODE
@ag123 , I know how it looks.
I just wanted to have from the op a simple sketch which shows the problem.
I just wanted to have from the op a simple sketch which shows the problem.
Re: Wait Serial1 transmission to complete CODE
---------------
Last edited by cpt_cyp on Tue Aug 24, 2021 10:39 pm, edited 1 time in total.
Re: Wait Serial1 transmission to complete CODE
there seem to be one thing that may be relevant, uart signals tend to be 'inverted', that down edge on serial output if i understand it correctly could be the *start bit*
https://arduino.stackexchange.com/quest ... ctive-high
the default line discipline is 8N1 in libmaple core, actually those flags won't change the line discipline if i read the codes correctly.
so if you need a different line discipline you may need to call other codes or set the registers directly
i'm not sure if it seems like the data has actually been successfully transmitted between the toggle on the enable pin as your codes suggests.
i.e. Serial1.flush() actually ran and returned.
it seemed as well (non stm32) uart implementations have 'weird caveats' some are expecting no gaps between bytes (more correctly) 8N1 frames transmitted, while stm32 allows and expects gaps between byte (8N1) frames
https://arduino.stackexchange.com/quest ... ctive-high
the default line discipline is 8N1 in libmaple core, actually those flags won't change the line discipline if i read the codes correctly.
so if you need a different line discipline you may need to call other codes or set the registers directly
i'm not sure if it seems like the data has actually been successfully transmitted between the toggle on the enable pin as your codes suggests.
i.e. Serial1.flush() actually ran and returned.
it seemed as well (non stm32) uart implementations have 'weird caveats' some are expecting no gaps between bytes (more correctly) 8N1 frames transmitted, while stm32 allows and expects gaps between byte (8N1) frames
Re: Wait Serial1 transmission to complete CODE
ive made a simple test using classic bluepill board and logic analyzer
here the sample code
both cores working well
STM32 HAL based core roger's libmaple based core purple is Serial1 TX pin
blue - PA3 pin (acts as tx enable pin for rs485)
P.s.
I hope your rotary_read is not an irq handler
here the sample code
Code: Select all
void setup() {
Serial.begin(115200);
Serial1.begin(115200);
pinMode(PA3, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
Serial.println("Starting...");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(PA3, HIGH);
Serial1.println("TEST");
Serial1.flush();
digitalWrite(PA3, LOW);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Sent...");
delay(1000);
}
STM32 HAL based core roger's libmaple based core purple is Serial1 TX pin
blue - PA3 pin (acts as tx enable pin for rs485)
P.s.
I hope your rotary_read is not an irq handler
Re: Wait Serial1 transmission to complete CODE
@stas2z
simple sketch is working well
but i dont know why my sketch is not working serial1.flush
maybe it stuck in rotary encoder routin..
i will find failure and post the solution
thank you soo much
simple sketch is working well
but i dont know why my sketch is not working serial1.flush
maybe it stuck in rotary encoder routin..
i will find failure and post the solution
thank you soo much