interrupts with UARTs

Questions on UARTs, and serial communication
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

interrupts with UARTs

Post by YahooArchive »

>from the help line
>I have one of your Pro+ boards and was wondering if Basic supports serial
interrupts rather than polling.

BASIC supports interrupts, by writing directly to the registers, and using
INTERRUPT SUB and ADDRESSOF keywords.

There are examples in the BASIClib directory subdirectories of Interrupt and
Interrupt/Cortex-M3

BASIC has builtin interrupts for UART0 and UART1 for received bytes. This code
is written in C, and source can be inspected by installing MakeItC and viewing
the cor_init.c files.

Since this was answered, all UARTs in BASIC use interrupts and have both input and output buffers



AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: interrupts with UARTs

Post by AMDlloydsp »

I have three SuperPro boards running Basic 8.25.

I cannot make them run TXD(1) on a buffered basis. If I wait() between characters, I can get the whole message out, but if I 'slam' the 'buffer' at the max loop rate with your example given in the BasicTools help, it loses all but the first character, because the entire output occurs before the first character has finished.

I presume I must somehow enable interrupt service, but there's nothing in the UART BASIC docs to point out how.

Thanks,
LS

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: interrupts with UARTs

Post by basicchip »

This actually sounds like what you are using to receive characters can not keep up.

In firmware versions before 8.25, TXD would wait between characters. 8.25 and beyond they are placed in a buffer and transmitted when the UART interrupts indicating that the transmitter is ready to send another character. In this mode characters are sent out one right after another with no delay in between. If that transmit buffer ever fills, at that point the ARM waits until there is room in the buffer.

The firmware version is reported in the Welcome message you see when you STOP a program or initially start BASICtools. The compiler version is reported in the About box in the Help Menu.

I know characters are not dropped on the transmit side, we have tested that extensively. What firmware and compiler versions are you using.

AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: interrupts with UARTs

Post by AMDlloydsp »

Thanks:
I'm running on the PC from which I program: ARMbasic[8.27d], BASICtools[5.19]
On the SuperPro board, ARMbasic kernal 8.25 with floating point.


First, I've tried this at even as slow as 110 baud.
Second, I know my custom terminal on a hardware port (no dongles) will keep up with 115200 with NO intercharacter delays, and only one stop bit.
Second-and-a-half, not even Hyperterm can be overrun at 110 baud, not even running on a USB dongle.
Third, I must just add (no brag, just fact) that I made my living for 25 years writing custom serial protocol converters for communicating between PCs and IBM mainframes, converting to/from BISYNC 3780 and/or HDLC/SDLC and RS232 at full, unfettered bit rates. So I'm pretty comfortable with plain-ole-serial... just not the ARMbasic.

So... I have all the tools to externally analyze what's happening on the pins. I've verified this behavior with a storage scope on the RS-232 output line of the SuperPro.

I'm obviously not including a file, or not setting up for interrupts correctly, or not allocating my Tx buffer correctly, or something.
Without delays at least as long as one character time, some or all characters are lost. Without the delays, the code finishes in "0" milliseconds, with them, in the time for the whole message (or the sum of the delays plus character times).

Oddly... if I set the inter-character delays at about half of one character time, I get about half the message. It's ALMOST as if the buffer is tiny, rather than the 128 bytes documented.

ARMbasic is not making me wait for the next character, so I have not over-filled the Tx buffer, nor is the message long enough to do that.

Finally, I can stream a file from any other source at full bit rates up to 115200 without overruns, just to check my terminal.

One thing I am not doing is controlling any flow-control pins. I've got RTS and DTR strapped true (hardwired) at the PC. This is a simple 3-wire interface.

Please tell me what I'm doing wrong.

Thanks,
LS

This is the code (no errors or warnings):
#include "./LPC17xx.bas"

#define TRAY_DISABLE 69
#define ARM_DISABLE 66

#define CR 13
#define LF 10





IO(TRAY_DISABLE) = 0
IO(ARM_DISABLE) = 0


RS232_test:

SUB PrintUART1 (Astr(100) as STRING)
DIM I as INTEGER
I=0
WHILE Astr(I)
TXD(1) = Astr(I)
print Astr(I);" ";
I=I+1
' Wait(200)
LOOP
TXD(1) = CR
' Wait(200)
TXD(1) = LF
END SUB


main:
IO(TRAY_DISABLE) =0
IO(ARM_DISABLE) =0

Baud(1)=110 ' enable UART1


PrintUART1 ("Hello Lloyd") ' Send a string of characters serially out UART1

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: interrupts with UARTs

Post by basicchip »

Here is a simple test case that shows we are not dropping characters. The hardware is a SuperPRO with firmware 8.25, compiler 8.27m (unreleased). IO(64) is shorted to IO(65) -- UART1 pins 8 characters are sent out in 12 microseconds, so we obviously are not waiting for the UART, and all 8 get received and then printed out within 4 msec, which is 8*10/19200 4.17 msec.

Code: Select all

 
Welcome to ARMbasic Kernel[8.25] with Floating Point            Copyright 2013, Coridium Corp.
  for the SuperPro  
 
baud(1)=19200

start = TIMER

txd(1)="a"
txd(1)="s"
txd(1)="d"
txd(1)="f"
txd(1)="j"
txd(1)="k"
txd(1)="l"
txd(1)=";"

print TIMER-start,"microseconds"

for i=1 to 8
  c = RXD(1)
  while c < 0
    c=RXD(1)
  loop
  print chr(c)
next i



Programming Flash 1756...
ARMbasic[8.27m] on the PC  Copyright 2013, Coridium Corp.
*+*+
... ( 0.22K code + 0.01K string)/96K   0.02/9K data programmed

Executing...

12	microseconds
a
s
d
f
j
k
l
;

... Finished in 4 ms

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: interrupts with UARTs

Post by basicchip »

I added this to the program

print "UART1 LCR", hex (*&H4001000C)

And it shows

UART1 LCR 3

Maybe your terminal needs more than 1 stop bit, which is bit 2 in that register, which you can change after the BAUD(1) statement.

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: interrupts with UARTs

Post by basicchip »

In our testing of the code we setup ARMs to echo what they saw on the serial port. Connected them to other ARMs streaming large amounts of DATA, as well as to PCs that were bursting variable lengths of data. Most all running at either 19.2 or 115 Kb. Done over a number of days, by 3 different people running independent test program they independently wrote. So we are pretty confident in it.

Also here is a scope trace of the first 2 characters going out, and it shows there is no delay between start and stop.
uartloop.jpg
uartloop.jpg (97.89 KiB) Viewed 22100 times

AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: interrupts with UARTs

Post by AMDlloydsp »

Obviously, something's different in our two compilers.

I get a compiler error when I add that line:

print "UART1 LCR", hex (*4001000C)
-ERROR tray_test_rs232_loopback.bas: 35: Expected End Of Line, found C)


print "UART1 LCR", hex (*4001000C)
-First ERROR at line :35

Is that a clue? Have I left out an include? (I am including LPC17xx.bas)
LS

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: interrupts with UARTs

Post by basicchip »

And I ran your program on my loopback setup, and added the readback of the characters, and it worked as expected. So I suspect some setting on your terminal is not allowing back to back characters.

PS - I did this with the WAIT(200) commented out, and that wait is 200 msec. when used in the program

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: interrupts with UARTs

Post by basicchip »

That line should have been

print "UART1 LCR", hex (*&H4001000C)

Post Reply