本文整理汇总了C++中USART_CR1函数的典型用法代码示例。如果您正苦于以下问题:C++ USART_CR1函数的具体用法?C++ USART_CR1怎么用?C++ USART_CR1使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了USART_CR1函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MB_USART_ISR
/* Find out what interrupted and get or send data as appropriate */
void MB_USART_ISR(void)
{
/* Check if we were called because of RXNE. */
if (((USART_CR1(MB_USART) & USART_CR1_RXNEIE) != 0) && ((USART_SR(MB_USART) & USART_SR_RXNE) != 0))
{
pxMBFrameCBByteReceived();
}
/* Check if we were called because of TXE. */
if (((USART_CR1(MB_USART) & USART_CR1_TXEIE) != 0) && ((USART_SR(MB_USART) & USART_SR_TXE) != 0))
{
pxMBFrameCBTransmitterEmpty();
/* Check if we need to disable transmitter*/
if(!txen)
{
USART_SR (MB_USART) &= ~USART_SR_TC; /* Clear TC flag*/
USART_CR1(MB_USART) |= USART_CR1_TCIE; /* Enable transfer complite interrupt*/
}
}
/* Disable transmitter on transfer comlite*/
if (((USART_CR1(MB_USART) & USART_CR1_TCIE) != 0) && ((USART_SR(MB_USART) & USART_SR_TC) != 0))
{
USART_CR1(MB_USART) &= ~USART_CR1_TCIE;/* Disble transfer complite interrupt*/
USART_SR (MB_USART) &= ~USART_SR_TC; /* Clear TC flag*/
/* Disable transmitter*/
gpio_clear(MB_USART_TXEN_PORT, MB_USART_TXEN_PIN);
}
}
示例2: DBG_USART_ISR
void DBG_USART_ISR(void)
{
/* Check if we were called because of RXNE. */
if (((USART_CR1(DBG_USART) & USART_CR1_RXNEIE) != 0) && ((USART_SR(DBG_USART) & USART_SR_RXNE) != 0))
{
usart_data = usart_recv(DBG_USART);
if( !dbg_fifo_write_byte( &usart_rx_buf, usart_data ) )
{
usart_disable_rx_interrupt(DBG_USART);
}
}
/* Check if we were called because of TXE. */
if (((USART_CR1(DBG_USART) & USART_CR1_TXEIE) != 0) && ((USART_SR(DBG_USART) & USART_SR_TXE) != 0))
{
/* Put data into the transmit register. */
if( dbg_fifo_read_byte( &usart_tx_buf, &usart_data ) )
{
usart_send(DBG_USART, usart_data);
}
else
{
/* Disable the TXE interrupt as we don't need it anymore. */
usart_disable_tx_interrupt(DBG_USART);
}
}
}
示例3: init
OPTL_NOINLINE
void init()
{
clk::enable();
rxpin::clock::enable();
txpin::clock::enable();
rxpin::init_alternate(afnum::af);
txpin::init_alternate(afnum::af);
rxpin::driver_pushpull();
txpin::driver_pushpull();
USART_BRR(base) = ((2 * cpuclock) + baudrate) / (2 * baudrate);
USART_CR1(base) &= ~USART_CR1_M; /* 8 data bits */
USART_CR1(base) = (USART_CR1(base) & ~USART_PARITY_MASK) |
USART_PARITY_NONE;
USART_CR2(base) = (USART_CR2(base) & ~USART_CR2_STOPBITS_MASK) |
USART_STOPBITS_1;
USART_CR3(base) = (USART_CR3(base) & ~USART_FLOWCONTROL_MASK) |
USART_FLOWCONTROL_NONE;
USART_CR1(base) = (USART_CR1(base) & ~USART_MODE_MASK) |
USART_MODE_TX_RX;
}
示例4: usart2_isr
void usart2_isr(void)
{
/* Check if we were called because of RXNE. */
if (((USART_CR1(USART2) & USART_CR1_RXNEIE) != 0) &&
((USART_SR(USART2) & USART_SR_RXNE) != 0)) {
/* Indicate that we got data. */
gpio_toggle(GPIOA, GPIO8);
/* Retrieve the data from the peripheral. */
ring_write_ch(&output_ring, usart_recv(USART2));
/* Enable transmit interrupt so it sends back the data. */
USART_CR1(USART2) |= USART_CR1_TXEIE;
}
/* Check if we were called because of TXE. */
if (((USART_CR1(USART2) & USART_CR1_TXEIE) != 0) &&
((USART_SR(USART2) & USART_SR_TXE) != 0)) {
int32_t data;
data = ring_read_ch(&output_ring, NULL);
if (data == -1) {
/* Disable the TXE interrupt, it's no longer needed. */
USART_CR1(USART2) &= ~USART_CR1_TXEIE;
} else {
/* Put data into the transmit register. */
usart_send(USART2, data);
}
}
}
示例5: usart1_isr
void usart1_isr(void)
{
unsigned char c;
/* Check if we were called because of RXNE. */
if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) &&
((USART_SR(USART1) & USART_SR_RXNE) != 0) &&
(!serial_rb_full(&srx))) {
c = serial_recv();
serial_rb_write(&srx, c);
}
/* Check if we were called because of TXE. */
else if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) &&
((USART_SR(USART1) & USART_SR_TXE) != 0)) {
if(!serial_rb_empty(&stx)) {
serial_send(serial_rb_read(&stx));
}
else {
/* Disable the TXE interrupt, it's no longer needed. */
USART_CR1(USART1) &= ~USART_CR1_TXEIE;
}
}
else {
c = serial_recv();
}
}
示例6: usart1_isr
void usart1_isr(void)
{
u8 ch;
//if Receive interrupt
if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) &&
((USART_SR(USART1) & USART_SR_RXNE) != 0))
{
ch=usart_recv(USART1);
buffer_put(&u1rx, ch);
}
if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) &&
((USART_SR(USART1) & USART_SR_TXE) != 0))
{
if (buffer_get(&u1tx, &ch) == SUCCESS)
{
//if char read from buffer
usart_send(USART1, ch);
}
else //if buffer empty
{
//disable Transmit Data Register empty interrupt
usart_disable_tx_interrupt(USART1);
}
}
}
示例7: usart_set_databits
void usart_set_databits(u32 usart, u32 bits)
{
if (bits == 8)
USART_CR1(usart) &= ~USART_CR1_M; /* 8 data bits */
else
USART_CR1(usart) |= USART_CR1_M; /* 9 data bits */
}
示例8: UART_IRQHandler
void UART_IRQHandler(struct CB_UART* pctl)
{
/* Receive */
if ((USART_SR(pctl->iuart) & USART_SR_RXNE) != 0) // Receive reg loaded?
{ // Here, receive interrupt flag is on.
*pctl->rxbuff_in = USART_DR(pctl->iuart);// Read and store char
/* Advance pointers to line buffers and array of counts and reset when end reached */
pctl->rxbuff_in = rxbuff_adv(pctl, pctl->rxbuff_in); // Advance pointers common routine
}
/* Transmit */
if ( (USART_CR1(pctl->iuart) & USART_CR1_TXEIE) != 0)
{ // Here, yes. Transmit interrupts are enabled so check if a tx interrupt
if ( (USART_SR(pctl->iuart) & USART_SR_TXE) != 0) // Transmit register empty?
{ // Here, yes.
USART_DR(pctl->iuart) = *pctl->txbuff_out;// Send next char, step pointer
/* Advance output pointer */
pctl->txbuff_out = txbuff_adv(pctl, pctl->txbuff_out);
/* Was the last byte loaded the last to send? */
if (pctl->txbuff_out == pctl->txbuff_in)
{ // Here yes.
USART_CR1(pctl->iuart) &= ~USART_CR1_TXEIE; // Disable Tx interrupt
}
}
}
return;
}
示例9: usart1_isr
void usart1_isr(void)
{
static uint8_t data = 'A';
/* Check if we were called because of RXNE. */
if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) &&
((USART_SR(USART1) & USART_SR_RXNE) != 0)) {
/* Indicate that we got data. */
gpio_toggle(GPIOA, GPIO6);
/* Retrieve the data from the peripheral. */
data = usart_recv(USART1);
/* Enable transmit interrupt so it sends back the data. */
USART_CR1(USART1) |= USART_CR1_TXEIE;
}
/* Check if we were called because of TXE. */
if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) &&
((USART_SR(USART1) & USART_SR_TXE) != 0)) {
/* Indicate that we are sending out data. */
gpio_toggle(GPIOA, GPIO7);
/* Put data into the transmit register. */
usart_send(USART1, data);
/* Disable the TXE interrupt as we don't need it anymore. */
USART_CR1(USART1) &= ~USART_CR1_TXEIE;
}
}
示例10: usart2_isr
void usart2_isr(void)
{
static u8 data = 'A';
/* Check if we were called because of RXNE. */
if (((USART_CR1(USART2) & USART_CR1_RXNEIE) != 0) &&
((USART_SR(USART2) & USART_SR_RXNE) != 0)) {
/* Indicate that we got data. */
gpio_toggle(GPIOD, GPIO12);
/* Retrieve the data from the peripheral. */
data = usart_recv(USART2);
/* Enable transmit interrupt so it sends back the data. */
usart_enable_tx_interrupt(USART2);
}
/* Check if we were called because of TXE. */
if (((USART_CR1(USART2) & USART_CR1_TXEIE) != 0) &&
((USART_SR(USART2) & USART_SR_TXE) != 0)) {
/* Put data into the transmit register. */
usart_send(USART2, data);
/* Disable the TXE interrupt as we don't need it anymore. */
usart_disable_tx_interrupt(USART2);
}
}
示例11: usart_set_databits
void usart_set_databits(uint32_t usart, uint32_t bits)
{
if (bits == 8) {
USART_CR1(usart) &= ~USART_CR1_M; /* 8 data bits */
} else {
USART_CR1(usart) |= USART_CR1_M; /* 9 data bits */
}
}
示例12: usart_set_mode
void usart_set_mode(uint32_t usart, uint32_t mode)
{
uint32_t reg32;
reg32 = USART_CR1(usart);
reg32 = (reg32 & ~USART_MODE_MASK) | mode;
USART_CR1(usart) = reg32;
}
示例13: usart_set_parity
void usart_set_parity(uint32_t usart, uint32_t parity)
{
uint32_t reg32;
reg32 = USART_CR1(usart);
reg32 = (reg32 & ~USART_PARITY_MASK) | parity;
USART_CR1(usart) = reg32;
}
示例14: usart_set_parity
void usart_set_parity(u32 usart, u32 parity)
{
u32 reg32;
reg32 = USART_CR1(usart);
reg32 = (reg32 & ~USART_PARITY_MASK) | parity;
USART_CR1(usart) = reg32;
}
示例15: usart_set_mode
void usart_set_mode(u32 usart, u32 mode)
{
u32 reg32;
reg32 = USART_CR1(usart);
reg32 = (reg32 & ~USART_MODE_MASK) | mode;
USART_CR1(usart) = reg32;
}