duff2013 / UartEvent

Event Based Hardware Serial for Teensy 3.1
18 stars 11 forks source link

RX interrupt (serial_dma_rx_isr) sometimes not fired #2

Open jymoulin opened 8 years ago

jymoulin commented 8 years ago

Hi, I'm using a teensy3.2 and UartEvent on TX2/RX2 with alternate port (pin 26 and pin 31 instead of pin 9 and pin 10). I updated Uart2Event to use CORE_PIN26_CONFIG and CORE_PIN31_CONFIG in serial_dma_begin() and serial_dma_end().

A UART GPS is connected to this two pin (26 and 31). The code using UartEvent is very simple:

Uart2Event GPS; GPS.txEventHandler = GPSTx; GPS.rxEventHandler = GPSRx; GPS.rxTermCharacterTrigger = '\n'; GPS.begin(38400);

GPSTx does nothing and GPSRx just copies available bytes into a buffer.

After a cold reboot, everything works fine.

Sometimes, after a soft reset (to upload new code), the GPS is sending data as usual but the serial_dma_rx_isr() doesn't start. As if it doesn't receive data on the RX pin.

What could go wrong (uart clock sync?) ? And how to 'reset' the DMA handler ?

Thank you !

Best, jym

duff2013 commented 8 years ago

I never used alt pins so I will have to investigate this, can you try the loopback example with the alt pins? Just make sure nothing is plugged into those pins when trying that example.

jymoulin commented 8 years ago

That's strange: the loopback example doesn't work, even without my modification for alternate pin. I tried Uart1, Uart2 and Uart3.

In fact, only one example is working: Fill_internal_buffer_time. The others: loopback, bufferSize, ReadBytesUntil doesn't.

The loopback example freezes because buffer is full (Event.availableForWrite() returns 0). The rxEvent() is never started.

I tried on a teensy3.2 (some devices connected and RTC crystal soldered but nothing on serial pin), and a teensy3.1 (nothing connected but RTC crystal soldered). My last board, without RTC, is a Teensy3.0, which cannot use UartEvent.

I'm using teensyduino version 1.27, arduino version 1.6.7.

duff2013 commented 8 years ago

I have the loop back working here for over an hour with no problems yet. Are you sure you didn't edit something else in the library? I'm using the current version on github and using latest Teensyduino and Arduino IDE. Probably should get you working with the examples before tackling your particular problem with the GPS unit.

jymoulin commented 8 years ago

I agree :-) So, I ran tests with a fresh install of Arduino-1.6.8, Teensyduino-1.28 and new clone of UartEvent.

The loopback example works only with teensy clock of 96Mhz (optimized or not). All other clock speed doesn't work.

Which clock are you using ?

duff2013 commented 8 years ago

That example is using 6MHz baud, try changing it something more reasonable like 115200 baud.

jymoulin commented 8 years ago

Ok, every clock speed works fine with 115200 baud. Even when using alternate pin (26 and 31) for TX2.

duff2013 commented 8 years ago

Good, at least this example works now. I should probably change that example baud rate to something all cpu speed can do:)