For a while now I have been messing around with the UART ports on the Vex Cortexes. Recently I have tried connecting two of them together to see if I could send and receive information. I started by using the code below on both of the Cortexes to send a char. Both would send and receive and I could check that by displaying to a LCD on the other UART port. Although I began to run into some issues rather quickly. When I would connect one into itself (Attaching the TX wire directly to the RX wire) I got a good reading. It would count up as it was supposed to. When I would connect the two Cortexes together this was not the case. I would only read zero on both of them. So I thought this had something to do with the timings, so I removed the wait1msec on one of the Cortexes and something strange happened. When I looked at the LCD with the one without the timings it would display numbers rapidly changing, however when I looked at the one with the timings it just showed me a zero. I have tried to look for a better understanding of how the “sendchar” and “receivechar” commands work but I do not get a clear answer. What I am wondering is if sendchar/receivechar waits for it to get a response, like a handshake, before continuing with the rest of the program. Any help would be appreciated! Thanks!
Here is the Code:
#pragma config(UART_Usage, UART1, uartUserControl, baudRate115200, IOPins, None, None)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task UARTReceive(){
int rcvChar;
while(true){
rcvChar = getChar(uartOne);
if(rcvChar == -1){
wait1Msec(3);
continue;
}
clearLCDLine(0);
clearLCDLine(1);
displayLCDNumber(0, 0, rcvChar);
wait1Msec(1000); //Timings I have been messing around with
}
}
task main()
{
long nTotalXmitChars = 0;
unsigned char xmitChar;
startTask(UARTReceive);
while(true){
++nTotalXmitChars;
xmitChar = nTotalXmitChars % 256;
sendChar(uartOne, xmitChar);
while(!bXmitComplete(uartOne)){
wait1Msec(1);
}
motor[6] = -127;
motor[7] = -127;
motor[8] = -127;
wait1Msec(1000); //Timings I have been messing around with
}
}