thanks for your input!
you are quite right about possibility to read last zeroed bit in error. i was mixing my code (a bit different) with one published her.
your suggestion to implement RXD when pinseq(1) :> void; really helped a lot, but this have not solved all issues I have right now.
let me define setup I have right now - GPS module connected to XC-2 card, the card connected to computer via JTAG. I am reading one byte from GPS module and sent it via JTAG, on computer I run HyperTerminal to read output.
if I use following rxByte() function implementation (wait for hi, wait for low, no read stop bit):
Code: Select all
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;
}
return (unsigned char)(data >> 24);
}
I get:
Code: Select all
$GPGLL,1929.93299,N,09907.82191,W,193Âr‚‚b
±
©ºšj
$GPRMC,193409.00,A,1929.93326,N,
09907.82147,W,1.907,,250210,,,A*6E
$GPVTG,,T,©Š)rÊ‚ºbr±šrªšŠbZ±
©’Âj
$GPGGA,193409.00,1929.93326,N,09907.82147,W,1,08
,1.22,2256.1,M,-7.5,M,,*6D
$uM±
±šb’²b‚ÊbŠ¢b’’bŠÂb’ŠbŠ5,24,,,,,2.07,1.22,1.67*06
$GPGSV,4,1,14,01,02,183,,03,10,310,,06,19,306,,09,& ÂÂbŠÂRº5
$GPGSV,4,2,14,1
4,41,223,14,15,11,037,11,18,47,356,27,21,69,029,29*7F
$GPGSV,ibŠ¢b’’bšºbš‚ºbš‚b’¢bªÊb‚Â’b’Êb’²b‚b’¢²bšŠb’ºb’Êb‚º¢bRº‚j
$GPGSV,4,4,14,
29,26,174,,30,00,163,*76
if i use (wait for low, end at middle of stop bit):
Code: Select all
unsigned char rxByte(in port RXD) {
unsigned data = 0;
timer t;
unsigned time;
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 */
t when timerafter ( time ) :> void ;
return (unsigned char)(data >> 24);
}
I get:
Code: Select all
$GPGLL,1929.93407,N,˜œœ˜›—œ™š™›–«–˜œ™›˜›—˜˜– –PJ“SHø$GPRMC,193608.00,A,1929.9340
3,N,09907.82438,W,0.616,–™š˜™˜˜––– •›¢†…’£¨«ª£––ª––SKLKMLMKSKLKLMLK)¥(%¦SHˆé
êê*Š
))š²‚Âr‚‚bŠÊ’ÊrÊš¢‚šbrb‚ÊÊ‚ºrÂ’¢šÂbº±Å±Áå±Å¹ÁͱÉÉÕݹå±5±µÝ¹Õ±5±±©Ùá5)‘AM±±Í±ÉÙ
±Áå±ÅÑXddXdnXdrXbpXdbXdhXXXXd\bp,1.03,1.93*0A
$GPGSV,4,1,14,01,02,182,,03,11,309,,0›–™˜–™˜š––˜œ–™š–˜œ›–˜š•›¢†…’ÕÔ•‰‰I‰)‰‰)‰‰
‰I‰II‰‰)i‰)©‰) ‰ šÂbbŠÂb¢ºbšªºb’ºb’Šb²Êb‚šŠbš‚Rº’jR":AMY±Ñ±Í±ÅѱÉɱÍݱÍÁ
å±ÍÁ±ÉѱÕå±ÁáѱÍÁ±ÉÙ±áűÉÕͱÉá±ÉnXdrX`nfXbjTnŠHŽ Ž¦¬XhXh,14,29,25,174,14,30,00
,162,*71
if I use (wait for low, end at stop bit's end):
Code: Select all
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);
}
I get:
Code: Select all
$GPRMC,193811.00,A,1929.œ™›œ˜–§–˜œœ˜›—œ™š™œ–«–˜—™‰Iª‚’Š‚bbb
©ÙÁ5)‘AYQ±±Q±±5±
Á¹ÉÝѱœX`\j`pX–X‚TdŒHŽ ŽŽ‚Xb93811.00,1929.93691,N,09œ˜›—œ™š™œ–«–˜–˜›–˜—™™–™™›L
ébj±µÝ¹Õ±5±±©ÙÁ5)‘AM±±ÍXdlXbhXddXdnXbpXdbXdhXXX,,,2.64,1.33,2.28*03
5)‘AMY±Ñ±É±ÅѱÅѱÑͱÉÉjXdfXbjXb`X`fpX`pXbpXhnX359,28,21,70,034,25*71
’£¨£©«–š–™–˜š–™™–™œ–™˜˜–¦&I¢bªÊb‚²b’ºb’²bŠb’²Šb’º±ÉݱÉå±ÁÝɱÅÁ©ÝÙ5)‘AMY±Ñ±Ñ±
ÅѱÉå±ÉÕ±ÅÝѱ±Í`X``XblbXTnnHŽ Ž˜˜Xbrd9.93691,N,09907.82428,W,˜œ™œ˜˜—˜˜– – •›¡†
…
I have tested GPS module by directly connecting module to TTL UART to USB FTDI adapter. Works just fine.
Please, let me know if I can provide any useful info.
Any comments are quite welcome as I really would like to learn XMOS very good.