Setup: XC-2 Ethernet board connected by 2 cables to Arduino UART's pins RX and TX, XC-2 connected via XTAG to computer.
On Arduino I run simple sketch which sends about 80 bytes, wait 1 sec, sends about 160 bytes, waits 1 sec, then sends about 240 bytes, waits 3 sec, repeat, via TX pin:
Code: Select all
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.write("-- about 80 bytes\r\n");
for(int i=33; i<127; i++) {
Serial.write(i);
}
Serial.write("\r\n");
delay(1000);
Serial.write("-- about 160 bytes\r\n");
for(int j=0; j<2; j++) {
for(int i=33; i<127; i++) {
Serial.write(i);
}
}
Serial.write("\r\n");
delay(1000);
Serial.write("-- about 240 bytes\r\n");
for(int j=0; j<3; j++) {
for(int i=33; i<127; i++) {
Serial.write(i);
}
}
Serial.write("\r\n");
delay(3000);
}
Code: Select all
/*
============================================================================
Name : xc2-uart.xc
Description : UART code for the XC-2 board
============================================================================
*/
#include <platform.h>
#define BIT_RATE 9600
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE
on stdcore[0]: out port PORTUART_TX = PORT_UART_TX;
on stdcore[3]: in port PORT_GPS_UART_RX = XS1_PORT_1B;
void txByte(out port TXD, unsigned char byte);
unsigned char rxByte(in port RXD);
void doUART(chanend c) {
unsigned char byte;
do {
c :> byte;
txByte(PORTUART_TX, byte);
} while(1);
}
void doGPS(chanend c) {
unsigned char byte;
do {
byte = rxByte(PORT_GPS_UART_RX);
c <: byte;
} while(1);
}
int main() {
chan c1, c2;
par {
on stdcore[0]: doUART(c1);
on stdcore[3]: doGPS(c1);
}
return 0;
}
void txByte(out port TXD, unsigned char byte) {
unsigned time, data;
timer t;
data = byte;
TXD <: 1;
/* get initial time */
t :> time;
/* output start bit */
TXD <: 0;
time += BIT_TIME;
t when timerafter(time) :> void;
/* output data bits */
for (int i=0; i<8; i++) {
TXD <: >> data;
time += BIT_TIME;
t when timerafter(time) :> void;
}
/* output stop bit */
TXD <: 1;
time += BIT_TIME;
t when timerafter(time) :> void;
}
unsigned char rxByte(in port RXD) {
unsigned data = 0;
timer t;
unsigned time;
RXD when pinseq(1) :> void;
RXD when pinseq(0) :> void;
t :> time;
time += BIT_TIME + ((BIT_TIME) >> 1);
// sample each bit in the middle.
for (int i = 0; i < 8; i++)
{
t when timerafter(time) :> void;
RXD :> >> data;
time += BIT_TIME;
}
/* input stop bit */
//time += (BIT_TIME >> 1) ;
//t when timerafter ( time ) :> void ;
return (unsigned char)(data >> 24);
}
Code: Select all
-- about 80 bytes
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnop
qrstuvwxyz{|}~
-- about 160 bytes
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnop
qrstuvwxyz{|}~!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ab
cdefghijklmnopqrstuvwxyz{|}~
-- about 240 bytes
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnop
qrstuvwxyz{|}~!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ab
cdefghijklmnopqrstuvwxyz{|}~!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRST
UVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Code: Select all
-- about 80 bytes
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVW•¥µÅÕåõ…‰‘•™¡¥©±µ¹½ÁÅÉ
ÍÑÕÙÝáåéíñõù5
-- about 160 bytes
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUV•¥µÅÕåõ…‰‘•™¡¥©±µ¹½ÁÅÉ
ÍÑÕÙÝáåéíñõù…"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcd
efghijk«Ëë
ÅÉÍÑÕÙÝáåéíñõù5
-- about 240 bytes
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUV•¥µÅÕåõ…‰‘•™¡¥©±µ¹½ÁÅÉ
ÍÑÕÙÝáåéíñõù…"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcd
efghijk«Ëë
ÅÉÍÑÕÙÝáåéíñõù…"*2:BJRZ,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX
YZ[\]^_`abcdefghijklmnopqrstu×åéíñõù5
Sorry, I have no idea what is going wrong.
Please, help!