Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 214 → Rev 215

/PIC Stuff/Cerebot_32MX7_LED_Cube/UART1.c
5,6 → 5,17
 
static UART1_DATA *uart_data_ptr;
 
/* Note: BRGH values are different from PIC18!
*
* Baud Rate Calculation (BRGH = 0):
* Baud Rate = PerfBusFreq / (16 * (BRG + 1))
* BRG = PerfBusFreq / (16 * Baud Rate) - 1
*
* Baud Rate Calculation (BRGH = 1):
* Baud Rate = PerfBusFreq / (4 * (BRG + 1))
* BRG = PerfBusFreq / (4 * Baud Rate) - 1
*/
 
void UART1_Init(UART1_DATA *data, void (*rx_callback)(char)) {
uart_data_ptr = data;
uart_data_ptr->rx_callback = rx_callback;
19,7 → 30,7
U1MODE = 0x00008000; // UART enabled, BRGH = 0
U1STA = 0x00009400; // TX interrupt on buffer empty, RX interrupt on buffer not empty
U1BRG = 19; // Set baud rate to 256000 @ 80MHz
U1BRG = 42; // Set baud rate to 115200 @ 80MHz
IEC0SET = 0x0C000000; // Enable the RX and Error interrupts
 
INTEnableInterrupts();
75,7 → 86,7
}
 
// Process UART1 transmit flag
if (IFS0bits.U1TXIF) {
if (IFS0bits.U1TXIF && IEC0bits.U1TXIE) {
// Disable the transmit interrupt if all data has been sent
if (uart_data_ptr->buffer_out_ind == uart_data_ptr->buffer_out_len) {
IEC0CLR = 0x10000000;