I am working on a project that requires UART communication between the dsPIC and an xbee module. When I run the code that I have, it compiles and programs but doesnt send anything over the UART line. I am just trying to get something to send over that signal line and then will work it up from there. Below is my main code as well as my UART1.c both were initially created by MCC within MPLABx. Thank you all in advance.
#include "mcc_generated_files/system.h"
#include "mcc_generated_files/uart1.h"
#include "mcc_generated_files/pin_manager.h"
#include "mcc_generated_files/clock.h"
#include "mcc_generated_files/dma.h"
#include "mcc_generated_files/ecan1.h"
#include "mcc_generated_files/interrupt_manager.h"
#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/reset.h"
#include "mcc_generated_files/reset_types.h"
#include "mcc_generated_files/system_types.h"
#include "mcc_generated_files/traps.h"
#include "mcc_generated_files/watchdog.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
int count = 1, i;
char string[30];
int main (void)
{
UART1_Initialize();
while(1)
{
printf(string,"c"); //
for(i = 0;i<sizeof(string);i++)
{
UART1_Write(string[i]);
}
count = count + 1;
}
}
UART1.c
#include "uart1.h"
#include <stdbool.h>
#include <stdint.h>
/**
Section: UART1 APIs
*/
void UART1_Initialize(void)
{
/**
Set the UART1 module to the options selected in the user interface.
Make sure to set LAT bit corresponding to TxPin as high before UART
initialization
*/
// STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled;
USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH
enabled; URXINV disabled; UEN TX_RX;
// Data Bits = 8; Parity = None; Stop Bits = 1;
U1MODE = (0x8008 & ~(1<<15)); // disabling UARTEN bit
// UTXISEL0 TX_ONE_CHAR; UTXINV disabled; OERR NO_ERROR_cleared; URXISEL
RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN disabled; ADDEN disabled;
U1STA = 0x00;
// BaudRate = 9600; Frequency = 40000000 Hz; BRG 1041;
U1BRG = 0x411;
U1MODEbits.UARTEN = 1; // enabling UARTEN bit
U1STAbits.UTXEN = 1;
}
uint8_t UART1_Read(void)
{
while(!(U1STAbits.URXDA == 1))
{
}
if ((U1STAbits.OERR == 1))
{
U1STAbits.OERR = 0;
}
return U1RXREG;
}
void UART1_Write(uint8_t txData)
{
while(U1STAbits.UTXBF == 1)
{
}
U1TXREG = txData; // Write the data byte to the USART.
}
uint16_t UART1_StatusGet (void)
{
return U1STA;
}
int __attribute__((__section__(".libc.write"))) write(int handle, void
*buffer, unsigned int len) {
int i;
while(U1STAbits.TRMT == 0);
for (i = len; i; --i)
{
while(U1STAbits.TRMT == 0);
U1TXREG = *(char*)buffer++;
}
return(len);
}