STM32F030C8T6 with quectel M35 in USART2 Receiving Problem
Hi,
I am STM32f030C8T6 MC along with L80 GPS in USART1 and Quectel Modem M35 in USART2 for live tracking purpose.The coding is done using COOCOX CO IDE. All Idone is I had successfully taken Latitude and Longitude from GPS and pushed to web-server using GPRS of the modem. upto this i had to prblm, the only problem is i cant able to read reply returned by modem to controller even using Interrupt . Here is the sample i have been trying for about two days,
#include <
stdint.h
>
#include <
stdio.h
>
#include <
stdio_ext.h
>
#include <
stm32f0xx_gpio.h
>
#include <
stm32f0xx_rcc.h
>
#include <
stm32f0xx_usart.h
>
#include <
semihosting.h
>
#include <
stm32f0xx_misc.h
>
#include <
string.h
>
#include <
math.h
>
char temp_buff[200]={'\0'};//,temp_buff1[200]={'\0'};
short irq_bit=0,okflag=0,data_received_bit=0,RMCGot=0,GGAGot=0,flag=0;
void USART1_IRQ(void)
{
char ch = 0;
static uint8_t SentenceBegin = 0, SentenceCnt = 0;
//static char TmpBuf[200];
if( USART_GetFlagStatus(USART1,USART_FLAG_RXNE)== SET)
{
USART_ClearFlag(USART1,USART_FLAG_RXNE);
ch=USART_ReceiveData(USART1);
if(ch=='$')
{
SentenceBegin=1;
SentenceCnt=0;
}
if(ch == '\n' && SentenceBegin)
{
printf(''%s \n'',temp_buff);
if(temp_buff[3]=='R' && temp_buff[4]=='M' && temp_buff[5]=='C')
{
RMCGot=1;
//gps_data(30,0);
//GGAGot=0;
}
if(temp_buff[3]=='G' && temp_buff[4]=='S' && temp_buff[5]=='V')
{
//RMCGot=0;
GGAGot=1;
}
SentenceBegin = 0;
flag=1;
}
if(SentenceBegin)
{
temp_buff[SentenceCnt] = ch;
SentenceCnt++;
}
}
}
void USART2_IRQ(void)
{
char c = 0;
static short SentenceB1 = 0, SentenceC1 = 0;
short size=0;
static char temp_buff1[200];
if( USART_GetFlagStatus(USART2,USART_FLAG_RXNE)== SET)
{
USART_ClearFlag(USART2,USART_FLAG_RXNE);
c=USART_ReceiveData(USART2);
if((c!='\n') && (c!='\0') && (SentenceB1==0))
{
SentenceB1=1;
SentenceC1=0;
irq_bit=1;
}
if(c == '\n' && SentenceB1)
{
temp_buff1[SentenceC1]='\0';
size=SentenceC1;
printf(''USART2:%s %d\n'',temp_buff1,SentenceC1);
if(temp_buff1[0]=='O' && temp_buff1[1]=='K')
{
okflag=1;
}
if((temp_buff1[0]=='d') && (temp_buff1[1]=='a') && (temp_buff1[2]=='t') && (temp_buff1[3]=='a') && (temp_buff1[4]==0x20) && (temp_buff1[5]=='r') && (temp_buff1[6]=='e') && (temp_buff1[7]=='c') && (temp_buff1[8]=='i') && (temp_buff1[9]='e') && (temp_buff1[10]=='v') && (temp_buff1[11]=='e') && (temp_buff1[12]=='d'))
{
data_received_bit=1;
}
{
for(int j=0;j<(size-1);j++)
{
temp_buff1[j]=0;
}
}
SentenceB1 = 0;
SentenceC1 = 0;
}
if(SentenceB1 && c!='\0')
{
temp_buff1[SentenceC1] = c;
SentenceC1++;
}
}
}
int main(void)
{
short j=0,k=0,first_flag=0;
uint8_t reg=0;
uint64_t i=0;
// short number[10]={0,0,0,0,0,0,0,0,0};
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef N;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); // Enable GPIO A bank clock
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); // Enable USART1 clock
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); // Enable USART1 clock
/* Configure Alternate Function pin muxing fabric to escape USART1 Rx and Tx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; // Green LED
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_1;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure USART1 pins: Rx and Tx */
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
// GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 |GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Enable USART1 IRQ */
/* Configure USART1 settings */
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_Init(USART1, &USART_InitStructure);
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(USART1, USART_OVRDetection_Disable);
USART_OverrunDetectionConfig(USART2, USART_OVRDetection_Disable);
USART_Cmd(USART1,ENABLE); // Enable USART1
USART_Cmd(USART2,ENABLE);
// 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);
// N.NVIC_IRQChannel = USART1_IRQn;
// N.NVIC_IRQChannelCmd = ENABLE;
// N.NVIC_IRQChannelPriority = 1;
// NVIC_Init(&N);
// NVIC_EnableIRQ(USART1_IRQn);
// USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
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);
USART2_IRQ();
while(1)
{
USART1_IRQ();
USART2_IRQ();
}
in the above i didnt used interrupt for USART2 , but i tried that one too. one more thing the Usart 1 works fine with Interrupt and without interrupt. the only prblm is Usart 2. When the modem is powered it reply with Call ready and Cpin ready, i cant able to read these things also.
#- #stm32f0 #quectel-m35