#include "rs485.h"
|
#include "delay.h"
|
|
#include "readdevicedata.h"
|
#include "devicegpioinit.h"
|
#include "gpio.h"
|
|
|
#define SEND_MAX_NUM 200
|
u8 share_sendbuf[SEND_MAX_NUM]={0};
|
/******************************************
|
* func: RS485_Usart_Init
|
* desc: RS485_Usart_Init
|
* input: system_BaudRate
|
* output: none
|
* return: none
|
*****************************************/
|
void RS485_Usart_Init(uint8 BaudRateCode,uint8 Parity)
|
{
|
uint32 system_BaudRate;
|
|
UART_SInitTypeDef UART_para;
|
CMU_ClocksType CMU_Clocks;
|
|
|
CMU_PERCLK_SetableEx(PADCLK, ENABLE);
|
AltFunIO(RS485_TXD_EN_PIN_GROUP, RS485_TXD_EN_PIN_NUM, ALTFUN_NORMAL);
|
AltFunIO(RS485_RXD_EN_PIN_GROUP, RS485_RXD_EN_PIN_NUM , ALTFUN_NORMAL);
|
//--------------------------------------------------------------------------------
|
|
UART_para.BaudRate = BaudRateCode;//²¨ÌØÂÊ
|
UART_para.StopBit = OneBit; //ֹͣλ
|
UART_para.DataBit = Eight8Bit; //Êý¾ÝλÊý
|
UART_para.ParityBit = Parity; //ÆæÅ¼Ð£Ñé
|
|
CMU_GetClocksFreq(&CMU_Clocks);
|
UART_SInit(UART1, &UART_para,&CMU_Clocks); //³õʼ»¯uart
|
|
// UARTx_IER_RXBF_IE_Setable(UART1, ENABLE);//½ÓÊÕ»º´æÂúÖжÏʹÄÜ ÐèҪʹÓýÓÊÕÖжϴò¿ª´Ë´¦ÉèÖÃ
|
// UARTx_IER_TXSE_IE_Setable(UART1, ENABLE)£»//·¢ËÍ»º´æ¿ÕÇÒ·¢ËÍÒÆÎ»¼Ä´æÆ÷¿ÕÖжÏʹÄÜ ÐèҪʹÓ÷¢ËÍÖжϴò¿ª´Ë´¦ÉèÖÃ
|
|
NVIC_DisableIRQ(UART1_IRQn);
|
// NVIC_SetPriority(UART1_IRQn,2);//ÖжÏÓÅÏȼ¶ÅäÖÃ
|
// NVIC_EnableIRQ(UART1_IRQn);
|
|
UARTx_CSR_RXEN_Setable(UART1, ENABLE); //´ò¿ª½ÓÊÕʹÄÜ
|
UARTx_CSR_TXEN_Setable(UART1, ENABLE); //´ò¿ª·¢ËÍʹÄÜ
|
|
UARTx_ISR_RXBF_Clr(UART1);
|
|
}
|
|
|
/******************************************
|
* func: RS485_Send_Data
|
* desc: send data by RS485
|
* input: USARTx - select USART port , buf - send buffer , len - data length
|
* output: none
|
* return: none
|
*****************************************/
|
void RS485_Send_Data(uint8 *buf,uint16 len)
|
{
|
uint16 t;
|
RS485_RE_H;
|
|
for(t=0;t<len;t++) //send data
|
{
|
UARTx_TXBUF_Write(UART4, buf[t]); //½«·¢ËÍÊý¾ÝдÈë·¢ËͼĴæÆ÷
|
while(RESET == UARTx_ISR_TXSE_Chk(UART4)); //µÈ´ý·¢ËÍÍê³É
|
}
|
|
while(RESET == UARTx_ISR_TXSE_Chk(UART4)); //µÈ´ý·¢ËÍÍê³É
|
|
RS485_RE_L;
|
}
|
|
/******************************************
|
* func: RS485_Receive_Data
|
* desc: get received data from RS485
|
* input: buf - receive buffer,len - data length
|
* output: none
|
* return: none
|
*****************************************/
|
void RS485_Receive_Data(uint8 * recbuf, uint8 *rec485buffer, uint8 len)
|
{
|
uint8 i=0;
|
|
for(i = 0;i < len;i ++)
|
{
|
recbuf[i] = rec485buffer[i];
|
}
|
}
|
|
|
/******************************************
|
* func: UART1_IRQHandler
|
* desc: UART1_IRQHandler
|
* input:
|
* output: none
|
* return: none
|
*****************************************/
|
//void UART1_IRQHandler(void)
|
//{
|
// u8 RX_dat;
|
|
// if((ENABLE == UARTx_IER_RXBF_IE_Getable(UART1)) &&(SET ==UARTx_ISR_RXBF_Chk(UART1)))
|
// {
|
// UARTx_ISR_RXBF_Clr(UART1);
|
// RX_dat=UARTx_RXBUF_Read(UART1);//½ÓÊÕÖжϱêÖ¾½ö¿Éͨ¹ý¶ÁÈ¡RXBUF¼Ä´æÆ÷Çå³ý
|
|
// LLJ_Msg.UartBuff[LLJ_Msg.WritePtr] = RX_dat;
|
// LLJ_Msg.WritePtr = (LLJ_Msg.WritePtr + 1) & 0xffff;
|
// }
|
//
|
|
//}
|