#include "MKL25Z4.h"
#include "main.h"
#include "uart.h"
#include <stdarg.h>
void UART0_init (void)
{
SIM_SCGC4 |= SIM_SCGC4_UART0_MASK;
SIM_SOPT2 |= SIM_SOPT2_UART0SRC(0x1) ;
SIM_SCGC5 |=SIM_SCGC5_PORTD_MASK;
PORTD_PCR6 = PORT_PCR_MUX(3);
PORTD_PCR7 = PORT_PCR_MUX(3);
UART0_C4 = 0x03; // baud rate = 19200 with 48MHz clock
UART0_BDL = 0xE8;
UART0_BDH = 0x03;
}
bool UART0_IsTxBufferEmpty(void)
{
return ( 0U != (UART0_S1 & UART0_S1_TDRE_MASK) );
}
bool UART0_IsRxBufferFull(void)
{
return (0U != (UART0_S1 & UART0_S1_RDRF_MASK) );
}
void UART0_PutTxDataBlocking(uint8_t txData)
{
UART0_C2 |= UART0_C2_TE_MASK;
while (UART_T_COMPLETE == 0){
; /* wait if transferring */
}
UART0_D = txData;
while (UART_T_COMPLETE == 0){
; /* wait if transferring */
}
UART0_D = (txData/256);
}
uint8_t UART0_GetRxData(void)
{
return (uint8_t)(UART0_D);
}
uint8_t UART0_GetRxDataBlocking(void)
{
while (!UART0_IsRxBufferFull() ) {}
return UART0_GetRxData();
}
能发送但是接收不了,到底哪里有问题,求大神
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>