Created Thu, 23 Feb 2012 10:01:04 +0000 by EratC
Thu, 23 Feb 2012 10:01:04 +0000
My system: Micro controller: PIC32 (pic32mx795f512l) Debugger: Pickit3 Expansion board: Digilent Chipkit Max32 Using MPLAB IDE v8.83
I am trying to modify and use the example code given with the PIC32MX UART Peripheral Library to be able to use the FTDI FT232R USB serial converter. According to the max32 reference manual, I have to use the UART1A (U1ARX,U1ATX) in the PIC32 microcontroller. However, when I try to modify the example code "uart_interrupt" to use UART1A, I get an error that UART1A is not declared. I read somewhere in this forum that UART1A is named as UART1. So I changed all the configuration to UART1.
Here is my code: -------BEGIN CODE-------------
#include #define GetSystemClock() (80000000ul) #define GetPeripheralClock() (40000000ul) #define GetInstructionClock() (GetSystemClock()/2) #define DESIRED_BAUDRATE (9600) //The desired BaudRate
int main(void) {
UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART1, GetPeripheralClock(), DESIRED_BAUDRATE); UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
while(1){
if(UARTTransmitterIsReady(UART1)) { UARTSendDataByte(UART1,0x55); } } }
-------END CODE---------------
But the U1TXREG remains 0 all the time. Can someone point me to the right direction and show me what I am doing wrong? I will appreciate it very much. Thank You
Sat, 25 Feb 2012 02:55:57 +0000
Hello,
I assume you're including plib.h and p32xxxx.h and any other necessary headers and setting the config bits? I would check your U1CON and U1STA registers to make sure they are behaving properly when you run your code. I personally much rather modify the registers directly than use Microchip's API calls.
e.g. #define bnOn 15 //You can define all the other bits of the UxCON register #define bnTrmt 8 //You can define all the other bits of the UxSTA register #define pbclk 40000000 #define baudUart1 2400 #define brgUart1 ( pbclk / ( 16 * baudUart1 ) ) - 1
int main(void) { U1CON = 0; U1BRG = brgUart1; U1CON = (1 << bnOn);
while(1) { if(U1STA & (1 << bnTrmt)) U1TXREG = 0x55; } }
Use this data sheet to help you out http://ww1.microchip.com/downloads/en/DeviceDoc/PIC32MX_Datasheet_v2_61143B.pdf I didn't compile this or anything so sorry if there is something I'm missing but you get my general point. I find this way to be easier to code and debug but to each their own :) .