Can not communicate with 300 baud rate

Hello,

I’ve a peculiar problem using usart (Serial1). I’ve modified the core firmware to initialize USARTserial as 8 bit, 1 stop bit, even parity, no flow control (it actually makes 7 data bits when you add a parity bit, according to documentation).

Anyways, it works just as expected when I initialize the baud rate anything higher than (including) 600. But when I try to initialize it with 300 baud rate, it does not communicate. I just receive garbled characters on the other end.

I’ve tried to test with several different computers and even a data logger that can record serial comm. but they all displayed garbled chars. Just as if the MCU can not clock its USART correctly.

I would like to state once more, any baud rate from 600 transmits and receives OK.

Do you have any ideas?

Not sure what settings you changed to get the baud rate to 300 but i’m looking at datasheet and you might want to calculate the error that might according that do a little adjustment to the value you use on USART_BRR and USARTDIV to minimize it

Another way i thought of is simply to run Serial1 as the normal 9bit, 1 stop first @ 300 to make sure things are working well 1st.

1 Like

Here is the changed initialization code for USART :

void USARTSerial::begin(unsigned long baud)
{
// AFIO clock enable
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

// Enable USART Clock
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

NVIC_InitTypeDef NVIC_InitStructure;

// Enable the USART Interrupt
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = USART2_IRQ_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

// Configure USART Rx as input floating
pinMode(RX, INPUT);

// Configure USART Tx as alternate function push-pull
pinMode(TX, AF_OUTPUT_PUSHPULL);

// USART default configuration
// USART configured as follow:
// - BaudRate = (set baudRate as 9600 baud)
// - Word Length = 8 Bits
// - One Stop Bit
// - No parity
// - Hardware flow control disabled (RTS and CTS signals)
// - Receive and transmit enabled
USART_InitStructure.USART_BaudRate = baud;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_None;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

// Configure USART
USART_Init(USART2, &USART_InitStructure);

// Enable USART Receive and Transmit interrupts
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);

// Enable the USART
USART_Cmd(USART2, ENABLE);

USARTSerial_Enabled = true;
transmitting = false;

}

Oh, sorry, the linewith
USART_InitStructure.USART_Parity = USART_Parity_None;

should have been

USART_InitStructure.USART_Parity = USART_Parity_Even;

I just pasted my test code. Anyways, it does NOT work with 7 bits data, 1 stop bit, even parity with 300 bauds. Any suggestions?

Hi kennethlimcp,

I was trying to use the Spark Core to communicate on a bus that’s using a baud rate of 500bps, and I am having the same problem, that 600bps was the lowest baud rate that would work. I was wondering if you knew how to modify the USART_BRR and USARTDIV registers to achieve lower baud rates. I was successful at using an Arduino to communicate with the other devices on the bus, so I know that 500bps will work.

Thanks for your time.

I took a quick look and it’s possible but only with local compiling since the spark cloud doesn’t support that. Will you be interested in doing that?

Yeah I have no problem to do that. Thanks for your help.

I’m interested as well. Thank you!

Just wondering that you meant Serial1.begin(500) did not work right?

Trying to figure out what’s up since the function seems to be implemented: https://github.com/spark/firmware/blob/feature/hal/platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/src/stm32f10x_usart.c#L235

Hi Kenneth,

Yes that’s correct. Sorry for the delay but I wanted to test it again.
Here’s the code I used to test with.

void setup() {

    Serial.begin(9600);
    Serial1.begin(500);

}

void loop() {
    
    while (Serial1.available())
    {
        Serial.print("Received: ");
        Serial.println(Serial1.read(), DEC);
        Serial1.flush();
    }
    
    delay(500);
}
```

I tested it with an Arduino sending bytes in a loop. When I set the baud rate on both devices to 500 I receive a "0" on the spark core, and when I set the baud to 600 or 9600 I receive the correct bytes the arduino is sending.

I know this is an old thread, but I was also trying to get the Photon to work with a device that only operates at 300 baud. Doing some digging it looks like it’s a hardware issue with the actual chip that wasn’t designed to go below 1200. The documentation however does list communication as anything from 300 - 115200. It should be noted that 115200 is the correct maximum.

USART protocol datasheets:
Core (STM32F103)
Photon / Electron (STM32F205)

The problem here is that the divisors can’t get the bus clock down low enough.

The slowest you can go is = bus clock / 4095 / 16. When the bus clock is 30MHz, that’s 457bps.
(4095 = maximum UART BRR divisor, 16 = UART oversampling)

If you slow the APB the UART is on down to 15MHz then you can get 300bps working. That’ll affect every peripheral on the bus though, which includes timers, other UARTs etc.

The UARTs go a LOT faster than 115,200 though - up to 3.75 or 7.5Mbps at the top end (divisor = 1, 8x oversampling, 60MHz bus clock).

2 Likes

I too realize this is an oldish thread, but I’ve been trying to hook up a Core to an old LED storefront display I have lying around. It communicates at 300 baud (8N2).

After spending a bunch of time wondering why I can’t get it working, and then finally trying to troubleshoot and noticing most stuff is working at 1200baud and up against a USB-Serial Adapter on my Mac, I arrived at this thread.

I found some other info on the Arduino forums (http://forum.arduino.cc/index.php?topic=57174.0) and didn’t know if that applied?

Is there a way to do 300baud comms on Serial1 (with a TTL-to-RS232 converter hooked up to Tx/Rx).

–mike

@Horganic, the Photon cannot support anything lower than 1200baud. You may be able to use @ScruffR’s ParticleSoftwareSerial library on Particle Build which seems to support 300baud. :wink:

2 Likes