Azure / azure-sphere-samples

Samples for Azure Sphere
Other
223 stars 200 forks source link

Azure sphere Uart baud rate change #256

Closed nishithvpoojary closed 1 year ago

nishithvpoojary commented 1 year ago

Hi. I have set the Uart baud rate in the azure starter kit as 460800. How can I change it to 115200. Does the UART library have function to change baud rate in the code. Thank you.

jamesadevine commented 1 year ago

For the HL core, you should call UART_Open with a UART_Config configuration struct. The configuration struct should be initialized using UART_InitConfig. After initialization, you can then set the baudRate member of the configuration struct to your desired baud rate before passing the struct to UART_Open.

See an example here: https://github.com/Azure/azure-sphere-samples/blob/42d2d155400c92eb825d4a1e3d9c629ea2906186/Samples/DeviceToCloud/ExternalMcuLowPower/AzureSphere_HighLevelApp/uart_transport.c#L126

nishithvpoojary commented 1 year ago

Thank you for your reply @jamesadevine . I have already set the UART config and opened the UART. Now I want to change the baud rate. Is it possible to change it later? Thank you.

jamesadevine commented 1 year ago

If you are experienced with low-level Linux calls, you should be able to modify the baud rate using termios. Here is an example

An alternative is that you should close the file descriptor and call UART_Open with your revised config!

nishithpoojary commented 1 year ago

Hi. Thank you @jamesadevine and sorry for late reply. How can I close it. Only UART open is available in UART configuration settings.

jamesadevine commented 1 year ago

@nishithpoojary just call close(fd); on the file descriptor returned by UART_Open!

nishithpoojary commented 1 year ago

@nishithpoojary just call close(fd); on the file descriptor returned by UART_Open!

It is working. Thank you @jamesadevine
I can't find any option to close this issue?

jamesadevine commented 1 year ago

I'll do the honours then 😄