AnsweredAssumed Answered

STM32F103 Usart data receive problem

Question asked by ohayo.John on Nov 25, 2016
Latest reply on Nov 25, 2016 by ohayo.John
Hello all,

Directly, I want to talk about a problem I have encountered.I am working on 2 types of microcontroller and I use stm32f103 model to get data from the other one via rs485.

So, For transmitting data from stm32f030 to stm32f103 , I am checking data transmition and if the correct data is being sent.In this part everything seems fine, the data is sent correctly.

Then I am trying to get this data with stm32f103 microcontroller.In this part I use USART1 for communication via rs485.     But unfortunately , during transmittion, stm32f103 does not indicate first character of the data and it continues untill the data transmission ends.

So, Inthis case I don't want to miss this first character and I don't want to get this same data again and again in one go.

Here is my receiving code of stm32f103(Expressions are available near codes)
extern "C" {
     
void USART1_IRQHandler(void)
    {
        if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)//Data available in the Read Register.
        //if(USART1->SR & USART_SR_RXNE)
        {
             
             
//          GPIO_SetBits(GPIOB,GPIO_Pin_0);
                GPIO_WriteBit(GPIOB,GPIO_Pin_0, Bit_RESET);//DE pin activation for receiving mode(rs485)
                char ch = rs485data.serialPort.getch();//USART1 "USART_ReceiveData(USART1);" method
             
//          if(ch!=50){
            if(ch!=10){//if there is no new line in incoming data
                 
                if(ch!=13){//if there is no carriage return in incoming data
                     
                rs485data.serialPort.rxTrailerbuffer[rs485data.serialPort.rxTrailerbufferReadCounter++]=ch;//fill buffer with character which comes from Usart1
             
            }}
//          }                      
                        if(rs485data.rs485detect== false){
                             
                        for (int i = 0;i<rs485data.serialPort.rxTrailerbufferReadCounter;i++){
                                         
                                        TrailerData[i]=rs485data.serialPort.rxTrailerbuffer[i];//After we get the data from Usart1, we set data from trailerbuffer to TrailerData
                                        rs485data.serialPort.rxTrailerbuffer[i]=0;//clear Trailer buffer
                        }
                        TrailerData[rs485data.serialPort.rxTrailerbufferReadCounter]=0;//clear Trailer Data
                        rs485data.rs485detect=true;
                        rs485data.serialPort.rxTrailerbufferReadCounter=0;//clear Trailerbufferreadcounter
//                     
//                      if(rs485data.serialPort.rxTrailerbufferReadCounter>6){
//                      rs485data.serialPort.rxTrailerbufferReadCounter=0;}
                         
                        }
                         
            //char ch = sp1.getch();
            USART_ClearITPendingBit(USART1, USART_IT_RXNE);//Clear pending bits for usart
                         
        }
    }
}

Here is , which data I want to send with stm32f030
com1234.gif

Here is, What I get with stm32f103.As you see the data is coming correctly.
com12345.gif

 This image is from my server, I am trying send this data (345) to server with GSM module and as ı mentioned above it skips first character of (345) in the beginning and add it to the end of this string.
453.gif 

Outcomes