forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

周巍
2024-04-11 91ef77c00ed797b1048c5187f416e351e646a009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
/******************************************************************************
 * 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);
}