Teensy as Serial device

0

I am using teensy 3.2 to program its K20 series microcontroller Mk20DX256 I have written a simple UART code to transmit a character 'U' from teensy to PC and see it on Docklight.I have disabled interrupt and DMA

I have searched through web and found out that Teensy acts as Serial port only when Serial type code is running Otherwise it acts as USB Port

I uploaded 'hello' example from arduino to board and chose Usb serial port This prints hello on serial monitor.the device is detected in COM PORT in hardware manager

But when i try to program my hex file generated from keil into the board The Com port option disappers from Port in hardware manager It means my code is not serial type

#include "MK20D7.h"

void UARTPutChar(char);

int main()
{
    
    SIM->SCGC4=1UL<<10; //Clock Enable Uart0
    SIM->SCGC5 =1UL<<12;//Enable GPIO PORT A clock
    UART0->C2=0X00;         //Disable UART 
    PORTD->PCR[7]=  0x00000300;     //Port pin declare as UART0TX
    UART0->BDH=0x01;    //
    UART0->BDL=0xD4;
    UART0->C1=0X00;
    UART0->C3=0X00; 
    UART0->S2=0X20;
    UART0->S1=0X40;
    UART0->C2=0X08; //Enable UART0
     while(1)    
  {        
       UARTPutChar('U');
   
  }

}

void UARTPutChar(char ch)
{
    if(UART0->S1  == 0X40)
    {
        
        UART0->D=ch;
    }
}

Anyone please guide what i am doing wrong.

teensy
asked on Stack Overflow Jan 15, 2021 by huzi • edited Jan 15, 2021 by huzi

1 Answer

0

If you compile for Teensy with Arduino, the build system will link in the Teensyduino core library which contains a working USB stack. Specifically, per default it will configure it as a CDC device (virtual serial port).

If you compile with Keil, I assume that you need to tell the IDE that you want to link in a USB stack and how you want it configured

answered on Stack Overflow Jan 15, 2021 by luni64

User contributions licensed under CC BY-SA 3.0