Serial1 not working on Grand Central M4


#1

Hi ,

I tried this small test to see signals on serial1 :

(defun test () (with-serial (str 1) (loop (write-byte 42 str))))

This should output ‘*’ continuously to serial1.
However nothing happens , just the pin goes from low to high.

If I upload a simple arduino sketch , than it works , so no board malfunction.

void (setup)
{
serial1.begin(115200);
}
void (loop)
{
Serial1.write('*'); 
}

What could be the problem here ?

Kind regards
Ronny


#2

I haven’t had a chance to test it yet, but have you tried:

(defun test () (with-serial (str 1 1152) (loop (write-byte 42 str))))

which would give you the same baud rate as the Arduino sketch?


#3

Hi David,

This puts a signal on the tx line , but it’s not what it should be
It outputs a square wave signal with a duty cycle of 50% with a frequency of about 33kHz.
42 = #x2a so it should be 00101010.
Also other values seem to give this strange behaviour.
I tested it again with the arduino sketch to be sure , and this outputs correct signals and frequency
I’ve uploaded 2 scope images to clarify. wave2 is the ulisp signal , wave4 is the arduino sketch.
Hope you have some info now , if you want anithing to test , please let me know.

Regards,
Ronny

WAVE2 WAVE4


#4

Hi Ronny,

I haven’t tested it on a scope, but I’ve connected it to my Tiny Terminal which is a 9600 baud serial display. Then I ran this program:

(defun test () (with-serial (str 1) (print "Hello Ronny" str)))

and it seems to work fine; I get this:

I’ve also looked at the uLisp code, but I can’t see anything odd; I’m just calling the Arduino routines.

I’m using ARM uLisp 2.9b.


#5

Hi David ,

Strange , but fine !
I will upload a 2.9b version from your site and start from scratch , and see what comes out.
I will keep you informed.

Thanks !
Regards,
Ronny


#6

Hi David ,

I know what’s wrong :-)
your “hello ronny” works also here , but not my former testprogram , unless I modify it to this :

(defun test ()
  (loop
    (with-serial (str 1) (write-byte 42 str) (delay 10))))

This rings a bell to me , we had this problem some time ago , It was something with closing the serial port to soon. That’s why a delay of 10ms (i picked it random) outputs indeed a ‘*’.
I will look in my emails how you solved this , or maybe you remember. ?

Regards
Ronny


#7

Hi David ,

see topic (with-serial) only works in a loop , posted by me .
here are the last messages.

johnsondavies

Sep '18

Hi Ronny,

After reading about Arduino Serial I think the correct solution is to add Serial1.flush() at the start of the definition of serialend() like this:

void serialend (int address) {
  Serial1.flush()
  ...
}

#8

That makes sense as the explanation, but I’ve just checked the definition of serialend() in uLisp 2.9b and it does indeed include Serial1.flush().

I’ll investigate. (I’ve trimmed your previous post).


#9

At 9600 baud characters are sent from the serial port at about 1000 per second, and about 10 times faster at 115200 baud. However, this is still much slower than the rate at which uLisp writes characters, so if you send characters to Serial the buffer may fill up, and what happens then depends on the Arduino implementation.

The safest thing is to put a small delay in the loop, such as:

(defun test () (with-serial (str 1) (loop (write-byte 42 str) (delay 1))))

#10

Hi David ,

I confirm that this is working.
Thanks for your help.

Kind regards ,
Ronny


#11