Hi,
I noticed a difference in the hardware schematic in this page: -
http://dangerousprototypes.com/wp-conte ... t-iiii.png (http://dangerousprototypes.com/wp-content/media/2009/12/cct-iiii.png)
where, the TX is connected pin-14, while RX connected to pin-15. But in the software, the settings are done vice versa. And, the software setting seem to be correct as thats how I get some signals out of the board (and RED LED blinks).
But I do not get the data out properly. I get a junk character, irrespective of any character that I send. The Receive seem to be working good as in debugger, I can see the correct data typed from my PC. But Transmit is always junk?? Any suggestion please.
Regards.
Issue solved by making changes to code: -
void UART1TX(char c){
// U1STAbits.UTXEN = 1; //Comments this line
while(U1STAbits.UTXBF == 1);
U1TXREG = c;
while(U1STAbits.TRMT== 0);
// U1STAbits.UTXEN = 0; //Commented this line
}
////////////////////////////////////////////////////////////////////////
void InitializeUART1(void){
//setup UART
U1BRG = 85;//86@80mhz, 85@79.xxx=115200
U1MODE = 0;
U1MODEbits.BRGH = 1;
U1STA = 0;
U1MODEbits.UARTEN = 1;
IFS0bits.U1RXIF = 0;
U1STAbits.UTXEN = 1; //Added this line of code, precisely here. Enabling TX elsewhere does not work
}
Strange, the original code works for me. What version compiler (lite, demo, trial? v3.xx?). Chip revision?
Just a follow up about this.
When using the C30 compiler v3.30b and TCP/IP stack v5.36, a delay needs to be introduced before disabling the TX enable register after each character in the UART1TX() function in MainDemo.c thus:
// Whoa! We need a delay here or the transmitted characters are garbled
// wait 15Ms before disabling the TX enable register bit.
DelayMs(15);
U1STAbits.UTXEN = 0; // disable TX to avoid backpowering FTDI chip when no USB attached
You also need to include the delay library header
#include "Delay.h"
at the start of the MainDemo.c file.
Note 1: This solution preserves the functionality of disabling TX to avoid backpowering the FTDI chip.
Note 2: Tested in the SD web demo program.
It may also pay to add a delay after enabling the UART TX register because:
The transmit pin is driven low as soon as the first data is written to the UxTXREG
register. To ensure the Start bit detection, it is recommended to have a delay between
enabling the UARTx (UARTEN = 1) and initiating the first transmission. The delay is baud
rate dependent and should be equal to or longer than the time it takes to transmit one
data bit. (Family Reference Manual page 17-14.)
though it seems to work without for now :)