TeensyLC Alternate UART0 / Serial1

Status
Not open for further replies.
Hello.

I am trying to use the alternate UART0 / hardware Serial1 pins based on the LC KL26 datasheet. Can anyone tell me if this is even the correct way to use these?

Code:
Serial1.begin(57600,SERIAL_8N1);
// Disable default pins
CORE_PIN0_CONFIG = 0;
CORE_PIN1_CONFIG = 0;
//TX - Alt4 usage UART0_TX
CORE_PIN24_CONFIG = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(4); //LC pin 24 /KL26 Pin 7 aka PTE20
//RX - Alt4 usage UART0_RX
CORE_PIN25_CONFIG = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(4); //LC pin 25 /KL26 Pin 8 aka PTE21

Next, I am trying to receive 20 bytes in my main loop which is very short. I choose when to send the 20 bytes and the data is garbled every time.
If I send the same 20 bytes, a few seconds apart, it's different every time. I have to use these pins because it's on PCB.
But I suppose I need to make sure that I'm using the Serial1 alternate pins properly, before moving on to receiving.

Code:
if(Serial1.available()>=20) { //wait until Rx buffer hits 20 bytes  - (8 data bit bytes)
    for (int b=0; b<20; b++)
    {
    myBuffer[b] = Serial1.read();  
    }
}

Any help would be super excellent.
 
Note, Paul added convenience functions to set the alternate RX and TX pins in Teensydunio 1.28: https://forum.pjrc.com/threads/3226...on-the-reference-cards-mean?p=98102#post98102, so you presumably would do:

Code:
Serial1.begin (57600, SERIAL_8N1);
Serial1.setRX (3);
Serial1.setTX (4);

I would probably try to do a read before all 20 bytes are available, buffering the data in myBuffer until you get the 20 bytes.

Thanks Michael. However, I don't believe that the "out-of-the-box" the setRX() and setTX() functions will work with this "ALT4" variation of Serial1. Serial1 seems to be UART0 and on the pin configuration sheet for the TeensyLC, I don't see that TeensyLC pins 24/A10 and 25/A11 are supported. But I came across this: https://forum.pjrc.com/threads/33524-custom-layout which is basically exactly what I'm trying to do, except on different pins. I'm trying to change the Pins for Serial1 aka UART0 because my buddy did a PCB layout and I'm stuck trying to use these pins (TeensyLC 24 and 25). I'll try reading just a single byte and get back.
 
Indeed, there were missing from serial1.c. I've added them, just now. ;)

https://github.com/PaulStoffregen/cores/commit/f5c6b360087ecd4b1c4a268f35739d8547f8dc1c

Please give the latest code a try and let me know if it works for you?

Awesome, Paul. Thanks, very much - you're a cool dude (as is this whole community).

I downloaded the updated "serial1.c" and put it into the "\Arduino\hardware\teensy\avr\cores\teensy3" directory and overwrote the original "serial1.c." Then I simply removed my previous serial1 initializations and added:
Code:
  Serial1.begin(57600, SERIAL_8N1);
  Serial1.setRX(25);
  Serial1.setTX(24);


Then I tried compiling and I get the following error and I'm not sure why yet (I did resave the file and then close and re-open the teensyduino app). Perhaps something with the AppData cache? I'm not sure:

Code:
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\libraries\TLC5951\TLC5951.cpp.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\libraries\SPI\SPI.cpp.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\memcpy-armv7m.S.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\memset.S.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\analog.c.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\eeprom.c.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\keylayouts.c.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\math_helper.c.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\mk20dx128.c.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\nonstd.c.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\pins_teensy.c.o
Using previously compiled file: C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\ser_print.c.o
"C:\Program Files (x86)\Arduino\hardware\teensy/../tools/arm/bin/arm-none-eabi-gcc" -c -Os -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD  -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -D__MKL26Z64__ -DTEENSYDUINO=128 -DARDUINO=10608 -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3" "C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\serial1.c" -o "C:\Users\JSCHEI~1\AppData\Local\Temp\build828c9c0f3486f78853ef5b9bf0034497.tmp\core\serial1.c.o"
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\serial1.c:199:6: error: conflicting types for 'serial_set_tx'

 void serial_set_tx(uint8_t pin, uint8_t opendrain)

      ^

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\serial1.c:33:0:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\HardwareSerial.h:117:6: note: previous declaration of 'serial_set_tx' was here

 void serial_set_tx(uint8_t pin);

      ^

Using library TLC5951 in folder: C:\Users\jscheiman\Documents\Arduino\libraries\TLC5951 (legacy)
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI 
Error compiling for board Teensy LC.
 
This error is the new serial1.c not agreeing with older files you have.

Try installing the latest 1.29-beta1. Then overwrite serial1.c.

Or replace all the files in the hardware/teensy/avr/cores folder with ones from github.
 
This error is the new serial1.c not agreeing with older files you have.

Try installing the latest 1.29-beta1. Then overwrite serial1.c.

Or replace all the files in the hardware/teensy/avr/cores folder with ones from github.

Yes, it works! Thank you. Also, initially, it took me a little while to realize that Serialx.available(); returns the buffer size starting with 0. So for my 20 bytes recieve, I wait until Serial1.available() returns 19. I haven't tried Tx, yet, though.
 
Status
Not open for further replies.
Back
Top