|
/******************************************************************************
|
* Copyright (C) 2014-2015 HangZhou SiZhu Co.,LTD.
|
*
|
*-----------------------------------------------------------------------------
|
* File: RS232.c
|
* Description: RS232 gpio config ,receive and send data code
|
* Author: Lishoujian (867693272@qq.com)
|
* Date: Jan 8, 2015
|
*****************************************************************************/
|
|
/* ----------------------- Platform includes --------------------------------*/
|
#include "RS232.h"
|
#include "stm32f10x.h"
|
#include "delay.h"
|
|
//#define DMA_RS232_TX
|
#define DMA_RS232_RX
|
|
RX_RS232_T rx_data_s_g;
|
|
//u8 tx232_buf[TX_NUM]= {0};
|
void GPRS_RS232_Usart_Init(uint32 system_BaudRate)
|
{
|
USART_InitTypeDef USART_InitStructure ;
|
DMA_InitTypeDef DMA_InitStructure;
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
|
USART_InitStructure.USART_BaudRate = system_BaudRate;
|
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(UARTRS232NUM , &USART_InitStructure );
|
USART_Cmd(UARTRS232NUM, ENABLE);
|
|
/*DMA½ÓÊÕ·¢Ëͳõʼ»¯*/
|
DMA_DeInit(DMA_RS232_RX_Channel);
|
/*ÉèÖÃDMAÔ´£º´®¿ÚÊý¾Ý¼Ä´æÆ÷µØÖ·*/
|
DMA_InitStructure.DMA_PeripheralBaseAddr =(u32)(&(UARTRS232NUM->DR)) ;
|
/*ÄÚ´æµØÖ·(Òª´«ÊäµÄ±äÁ¿µÄÖ¸Õë)*/
|
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)(rx_data_s_g.RS232_RX_TEMP_BUF);
|
/*·½Ïò£º´ÓË«Ïòµ½ÄÚ´æ*/
|
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
|
/*´«Êä´óСDMA_BufferSize=SENDBUFF_SIZE*/
|
DMA_InitStructure.DMA_BufferSize = RX232_LENGTH;
|
/*ÍâÉèµØÖ·²»Ôö*/
|
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
/*ÄÚ´æµØÖ·×ÔÔö*/
|
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
/*ÍâÉèÊý¾Ýµ¥Î»*/
|
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
/*ÄÚ´æÊý¾Ýµ¥Î» 8bit*/
|
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
/*DMAģʽ£º²»¶ÏÑ»·*/
|
//DMA_InitStructure.DMA_Mode = DMA_Mode_Normal ;
|
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
|
/*ÓÅÏȼ¶£ºÖÐ*/
|
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
|
/*½ûÖ¹ÄÚ´æµ½ÄÚ´æµÄ´«Êä */
|
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
|
|
DMA_Init(DMA_RS232_RX_Channel, &DMA_InitStructure);
|
USART_DMACmd(UARTRS232NUM, USART_DMAReq_Rx, ENABLE);
|
DMA_Cmd(DMA_RS232_RX_Channel, ENABLE);
|
|
// USART_ClearITPendingBit(UARTRS232NUM, USART_IT_TC);//Çå³ýTC±êÖ¾
|
|
}
|
|
|
/******************************************
|
* func: gprsuart_sendbyte
|
* desc: send data by RS232
|
* input: USARTx - select USART PORT , buf - receive buffer , len - data length
|
* output: none
|
* return: none
|
*****************************************/
|
|
void gprsuart_sendbyte(unsigned char dat)
|
{
|
while(USART_GetFlagStatus(UARTRS232NUM,USART_FLAG_TC) == RESET);
|
USART_ClearFlag(UARTRS232NUM,USART_FLAG_TC);
|
USART_SendData(UARTRS232NUM,dat);
|
}
|