AnsweredAssumed Answered

STM8S003F3P6 UART1  is not working???

Question asked by Chayan Roy on Nov 14, 2017

Hello everyone,

I am trying to  receive   receive a hex data (0x20) from the uart1 port of STM8S003F3P6 , from another microcontroller's TX pin. Connection is as follows:

 

STM8S003F3P6                   AVR MCU

    RX <------------------------->  TX

    TX <------------------------->RX

  AVR MCU is working with 5V Supply and STM8S003F3P6 is woring on 3.3V supply

Problem  is AVR UART is working fine,its  sending and receiving uart data. But  at STM8S003F3P6 side there is nothing happening .  Here is the code below:

 

 

 

 

#include "STM8S003F3P.h"

 

void InitialiseSystemClock(void);

 

void UART1_Initialize(void);

 

 

 


    
void UART1_Initialize(void){

 

    UART1_CR1 = 0;
    UART1_CR2 = 0;
    UART1_CR4 = 0;
    UART1_CR3 = 0;
    UART1_CR5 = 0;
    UART1_GTR = 0;
    UART1_PSCR = 0;
    UART1_CR1 =(0<<4);
    UART1_CR1=(0<<2);
    UART1_CR3=(0<<4)|(0<<5);
    
    UART1_BRR2     =0x0A;      //  Set the baud rate registers to 14400
    UART1_BRR1     = 0x08;
    UART1_CR2=(0<<3);
    UART1_CR2=(0<<2);
    UART1_CR3=(1<<2)|(1<<1)|(1<<0);
    UART1_CR2=(1<<5);
    UART1_CR2=(1<<2)|(1<<3);

 

    UART1_CR3=(1<<3);

 

 

 

}

 

 

 

void main(void){

 

                   InitialiseSystemClock();
                                                       
    
                    
                                
              UART1_Initialize();
                

 

        PC_ODR &=~(1<<4);
                                        

 


                 _asm("rim");
                   
                                 while(1){
                                             
                    
                                        
            
                                 }

 


}

 

 

 

 

 

@far @interrupt void UART1_RECV_INTERRUPT (void) {  //vector18-UART1 RECEIVE INTERRUPT HANDLER

 

while(!(UART1_SR & (1<<5)));
read=UART1_DR;
if(read==0X20){

 

PC_ODR ^=(1<<4);

}

 

}

void InitialiseSystemClock(void)
                         {
                            CLK_ICKR = 0;                       //  Reset the Internal Clock Register.
                               CLK_ICKR = (1<<0);;                 //  Enable the HSI.
                            CLK_ECKR = 0;                       //  Disable the external clock.
                             while (!(CLK_ICKR & (1<<1)));       //  Wait for the HSI to be ready for use.
                               CLK_CKDIVR = 0;                     //  Ensure the clocks are running at full speed.
                               CLK_PCKENR1 = 0xff;                 //  Enable all peripheral clocks.
                                   CLK_PCKENR2 = 0xff;                 //  Ditto.
                                      CLK_CCOR = 0;                       //  Turn off CCO.
                                      CLK_HSITRIMR = 0;                   //  Turn off any HSIU trimming.
                                         CLK_SWIMCCR = 0;                    //  Set SWIM to run at clock / 2.
                                          CLK_SWR = 0xe1;                     //  Use HSI as the clock source.
                                          CLK_SWCR = 0;                       //  Reset the clock switch control register.
                                     CLK_SWCR = (1<<1);                  //  Enable switching.
                                 while (CLK_SWCR & (1<<0));        //  Pause while the clock switch is busy.
                                    }

 

 

Logic is when ever Data is received a led is connected to PORTC-4,toggles its state. Kindly help me. Thanks.

Outcomes