AnsweredAssumed Answered

STM32F030C8T6 with M35 Modem Usart2 Receiving Problem

Question asked by c.rajeshkumar on Nov 14, 2016
Latest reply on Nov 14, 2016 by c.rajeshkumar
Hi,

I have connected STM32f030c8t6 with M35 modem using Usart 2 , Stn32f0 transmits the Command Successfully, but it can't retrive the reply given by the modem. This my code. I have tested this code with shorting RX and TX of Stm32f0 , by transmitting a string and receiving it successfully. I didn't get it where i am going wrong in this code.
#include <stdint.h>
#include <stdio.h>
#include <stm32f0xx_gpio.h>
#include <stm32f0xx_rcc.h>
#include <stm32f0xx_usart.h>
#include <semihosting.h>
#include <stm32f0xx_misc.h>
#include <string.h>
 
#define MAX_BUFFER_SIZE     256
 
typedef struct Buffer_st
{
   uint8_t size;
   char data[MAX_BUFFER_SIZE];
}Buffer_st;
 
Buffer_st receivedDataUART2;
 
 
char temp_buff1[300]={'\0'};
volatile uint8_t OKGot = 0,GGAGot=0;
short flag=0,irq_bit=0;
 
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount);
void UART_Send1(const unsigned char pucBuffer, unsigned long ulCount);
void resetReceivedDataBufferUART2(void);
 
void USART2_IRQHandler(void)
{
    uint8_t j=0;
  // if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
   {
       receivedDataUART2.data[receivedDataUART2.size++] = (char)USART_ReceiveData(USART2);
 
       if(receivedDataUART2.size == MAX_BUFFER_SIZE)
       { resetReceivedDataBufferUART2();
           receivedDataUART2.size=0;
       }
   }
   printf("U2: %s \n",receivedDataUART2.data);
 
}
 
void resetReceivedDataBufferUART2(void)
{
   receivedDataUART2.size = 0;
   memset(receivedDataUART2.data, MAX_BUFFER_SIZE,  receivedDataUART2.size);
}
 
 
 
int main (void)
{
  const unsigned char init[]="AT\r\n";
  const unsigned char init8[]="ATD*111#\r\n";
  const unsigned char init9[]="ATE1\r\n";
 
  int64_t i=0;
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef N;
 
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
 
 
  //Configure USART2 pins:  Rx and Tx ----------------------------
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_3 | GPIO_Pin_2;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
      GPIO_Init(GPIOA, &GPIO_InitStructure);
 
      GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
      GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
 
USART_DeInit(USART2);
 
      USART_InitStructure.USART_BaudRate = 9600;
           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
           USART_InitStructure.USART_StopBits = USART_StopBits_1;
           USART_InitStructure.USART_Parity = USART_Parity_No;
           USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
           USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
 
      USART_Init(USART2, &USART_InitStructure);
 
      USART_OverrunDetectionConfig(USART2, USART_OVRDetection_Disable);
 
        USART_Cmd(USART2,ENABLE);
 
// INterrupt for USART2
        N.NVIC_IRQChannel = USART2_IRQn;
               N.NVIC_IRQChannelCmd = ENABLE;
             N.NVIC_IRQChannelPriority = 0;
            NVIC_Init(&N);
               NVIC_EnableIRQ(USART2_IRQn);
              USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
              resetReceivedDataBufferUART2();
 
// power of the modem init
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; // Green LED
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_1;
 
     GPIO_Init(GPIOB, & GPIO_InitStructure);
 
     GPIO_WriteBit(GPIOB, GPIO_Pin_14,Bit_SET);
     for (i=0; i<2500000;i++);
     GPIO_WriteBit(GPIOB, GPIO_Pin_14, Bit_RESET);
 
 
     for (i=0; i<3000000;i++);
 
 
 
     resetReceivedDataBufferUART2();
 
     for(i=0;i<(SystemCoreClock/1920);i++);
 
     UARTSend(init,(sizeof(init)-1));    // AT command
 
     for(i=0;i<(SystemCoreClock/1920);i++);
 
     UARTSend(init9,(sizeof(init9)-1));    // ATE1 command
 
    for(i=0;i<(SystemCoreClock/1920);i++);
 
     UARTSend(init8,(sizeof(init8)-1));   // ATD*111# command
 
  while(1)
  {
 
 
 
  }
 
 
}
 
 
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
 
 
    while(ulCount--)
    {
        USART_SendData(USART2,(uint16_t) *pucBuffer++);// Last Version USART_SendData(USART1,(uint16_t) *pucBuffer++);
        /* Loop until the end of transmission */
        while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
        {
        }
    }
 
}
 
 
 
void UART_Send1(const unsigned char pucBuffer, unsigned long ulCount)
{
 
    while(ulCount--)
    {
        USART_SendData(USART2,(uint16_t) pucBuffer);// Last Version USART_SendData(USART1,(uint16_t) *pucBuffer++);
        /* Loop until the end of transmission */
        while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
        {
        }
    }
}

Outcomes