[mc1322x] problems with the UART
Jim Paris
jim at jtan.com
Mon Jan 4 23:39:41 EST 2010
Jon Smirl wrote:
> Why won't this loop work without messing up the printout?
> It gets 32 chars right and then messes up. 32 chars is the size of the FIFO.
>
> for (i = 0; i < 10; i++) {
> for (j = 'A'; j <= 'z'; j++) {
> reg32(UART1_DATA) = j;
> if (reg32(UT1CON) == 0) { // stop when FIFO is full
> while (reg32(UT1CON) != 31) { // wait for it to empty
> }
> }
> }
> reg32(UART1_DATA) = '\n';
> }
Your numbers "0" and "31" seem strange. The MC1322xRM says that
0=full, 32=empty and even mentions "if this value goes negative.." so
there may be other values present. What it does say is "data can be
written to the transmit buffer while this number is non-zero", which
suggests:
for (i = 0; i < 10; i++) {
for (j = 'A'; j <= 'z'; j++) {
while (reg32(UT1CON) == 0)
continue;
reg32(UART1_DATA) = j;
}
while (reg32(UT1CON) == 0)
continue;
reg32(UART1_DATA) = '\n';
}
btw. your original code can write two characters ('\n', 'A') with no
checks of UT1CON in between. It's also not clear that UT1CON will
necessarily show an updated value in the cycle immediately following a
write. Best to follow their prescribed method...
-jim
More information about the mc1322x
mailing list