baud rate set

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

baud rate set

2,007 Views
jjl3
Contributor I
hardware:smileyvery-happy:SP56F801A60
software: Codewarrior 7.2
 
I used PE to generate a program of UART, baud rate is 9600.
it can work normally.
when I write myself, it always can't work normally. I set register as same as that program generated by PE.
 
this is program I wrote,
I always can't communicate with PC,
Please help me! 
 
#include"56801.h"
typedef unsigned int word;
void SCI0_SendChar(unsigned char);
void main(void)
{
 asm
 {
   bfset             #$40,X:smileyvery-happy:FIU_CNTL
   bfset             #$103F,X:ISOCTL
   bfclr             #$FFBF,X:smileyvery-happy:FIU_CNTL
   bfclr             #$FFFB,X:smileytongue:LLCR
 };
 
 while(*((word *)(PLLSR)) & 0x4 ){}
 
 asm
 { 
      move              #$81,X:smileytongue:LLCR
      move              #0,X:CLKOSR
      move              #$11D,X:smileytongue:LLDB
    };
 
 while(!(*((word *)(PLLSR)) & 0x20)){}
 
 asm
 {
   move              #$82,X:smileytongue:LLCR
 
      bfclr             #6,X:GPIO_A_PER
      bfset             #6,X:GPIO_A_DDR
      bfclr             #6,X:GPIO_A_DR
   
      move              #0,X:smileyfrustrated:YS_CTRL
      orc               #3,X:GPIO_B_PER
      move              #0,X:smileyfrustrated:CI0_SCICR
      move              #$00c3,X:smileyfrustrated:CI0_SCIBR
      orc               #8,X:smileyfrustrated:CI0_SCICR
      bfset             #$0100,SR
      bfclr             #$0200,SR
 };
     
      SCI0_SendChar('H');
   SCI0_SendChar('e');
   SCI0_SendChar('l');
   SCI0_SendChar('l');
   SCI0_SendChar('o');
   SCI0_SendChar('!');
   SCI0_SendChar('\n');
 
 while(1)
 {
  
 }
}
void SCI0_SendChar(unsigned char chr)
{
    while(!(*((word *)(SCI0_SCISR)) & 0x8000)){}
    *((word *)(SCI0_SCIDR)) = chr;
}
 
Labels (1)
0 Kudos
1 Reply

475 Views
nikfo
Contributor I
Hi!
I am not using the sam processor as you are, but write to UART should be rather like.

My program look like this:

void SCI0_SendChar(char WriteBuffer){
While(!(SCI0SR1 & SCI0SR1_TDRE_MASK)){;}// Wait until TX buff empty SCI0DRL = WriteBuffer;
}

Works like a charm. In your program you use a lot of pointers and casting. I am not that into programming so i cant say if it is wrong or not. Take a look in your datasheet, maybe you have to do this way.

Compare your send command with mine:
*((word *)(SCI0_SCIDR)) = chr;
SCI0DRL = WriteBuffer;

I am using only 8 bit UART so i stay with char.
No final solution for you, but maybe a push in some direction =).

//Niklas
0 Kudos