Page 1 of 1

uart baud rate

PostPosted: Wed Apr 20, 2011 5:12 am
by linkinpark32123
Where do you change the Uart baud rate in the sample code SD1. I know it is default set to 9600, the camera we are using 14400. I was looking in the Uart .c and .h files and I see where the comments says it defines the baud rate but I am unsure how it is actually doing it.

Thanks

Re: uart baud rate

PostPosted: Wed Apr 20, 2011 6:10 am
by aek
The way the UART code works is that the initializer fills the registers associated with the UART with the values required to achieve the desired settings.

The strings in uart.h are those register values.

Therefore, if one that you need isn't already defined in uart.h, you simply need to create (i.e. #define) a new set of symbols that do what you want. I suggest that you keep your symbol separate from those in uart.h, but send it in and I can incorporate it into a future release.

Re: uart baud rate

PostPosted: Wed Apr 20, 2011 7:24 am
by linkinpark32123
Yes I understand that. I cant find where the baud rate variables are defined that you use in the define statement UART_9600_N81_MAIN in dspic33_uart.h. I am looking in the dspic33_uart.h file and am looking at the uart_dis_abaud and believe this is the value that needs to change. I can not find anywhere where this is defined. Is it in the library file?

Thanks

Re: uart baud rate

PostPosted: Wed Apr 20, 2011 11:18 am
by aek
Any predefined values other than simple numercial constants are defined within the Microchip C30 header files associated with the libraries.

In the Microchip MPLAB C30 doc folder, there's a Windows help file that covers all of the PIC24 libraries. The dsPIC33 stuff is handled differently, in html files, IIRC.

IOW, Microchip defines all of those symbols.

Re: uart baud rate

PostPosted: Wed Jan 30, 2013 4:42 am
by yiqi
Hi, I think the in define statement
#define UART_9600_N81_MAIN UART_RX_INT_EN & UART_RX_INT_PR7 & UART_TX_INT_DIS & UART_TX_INT_PR7, \
UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & UART_MODE_FLOW & UART_UEN_00 & UART_DIS_WAKE & \
UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE & UART_BRGH_SIXTEEN & UART_NO_PAR_8BIT & \
UART_1STOPBIT, \
UART_INT_TX & UART_IrDA_POL_INV_ZERO & UART_SYNC_BREAK_DISABLED & UART_TX_ENABLE & \
UART_INT_RX_CHAR & UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR, \
((MAIN_XTAL_FREQ/(32*9600L))-1)


9600 in the last line is the place you can change baud rate. Pls correct if I'm wrong :)

Re: uart baud rate

PostPosted: Wed Jan 30, 2013 11:33 am
by aek
Yes, you are correct, but there are some assumptions as to how the clock is setup, and which prescalars are in force. Those (at least, in terms of the UART peripheral) are all controlled via that #define, so you should be able to get to a variety of baud rates simply via minor changes ...