0

I am new to Cortex M4 programming I am using teensy 3.2 board .I have connected it to PC using USB to TTL cable.I have written a code to transmit a character from Teensy UART to PC .I am using Dockight as terminal. The baudrate is 9600 for a 72MHZ system clock with 8 data bits ,1 start bit,1 stop bit and no parity bit. I have disabled interrupts and DMA Here is my code

   #include "MK20D7.h"


void UARTPutChar(char);

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

}

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

I have configured Docklight settings correctly but i dont receive the character i transmit Here is what i getenter image description here Whereas I should receive Ascii of 'A'.I have my self let the Transmit Empty Flag unused for checking. When i used S1 status flag,nothing is transmitted to PC.

huzi
  • 1
  • 1
  • 1
    start with 8N1 and transmit 0x55 this will create a square wave which will not have any framing/parsing problems. you may simply be sampling it shifted. – old_timer Jan 20 '21 at 18:22
  • cortex-m4 has nothing to do with any of this – old_timer Jan 20 '21 at 18:28
  • you dont want to jam the register like that, use a timer or delay loop to delay, and then once you figure out and can confirm exactly how the transmit buffer empty/full flags work (usually work as expected, sometimes not) then use those to transmit continuously. – old_timer Jan 20 '21 at 18:29
  • This is the point where a DSO is rather useful – marko Jan 20 '21 at 23:08
  • Thank you for reply I have tried sending 0x55 but i receive 0x38 ..I also added a delay but i receive the same with delay ...I don't have any debugger connected with keil as i am using Simulation So i cannot view the changes in registers and status flags. How should i proceed now.Please help – huzi Jan 21 '21 at 04:52
  • Can you please help me with verifying BDH and BDL registers .I have doubt in it. Uart clock 72MHZ baudrate is 9600 .please help me in calculating correct values of BDH and BDL using the formula :baud rate= UART Clk/(16 *(SBR + BRFD)) – huzi Jan 21 '21 at 07:32
  • Can you attach link to data sheet/reference manual. Where are you setting data bits, parity and stop bit. – Dark Sorrow Jan 26 '21 at 10:55

0 Answers0