I'm trying to configure a UART ISR.
I using MQX, but here I want to control the ISR directly.
The ISR doesn’t work when I start writing. (after sending one byte It doesn’t enter to the ISR )
Can You see if there is something missing in my configuration.
Michael David.
Here is my UART Configuration:
void Uart_InitUart(void)
{
uint_16 ubd,temp0,temp1,brfa;
uint_32 sysclk = BSP_SYSTEM_CLOCK, baud0 = 57600;
//UART configuration
SIM_SCGC4 |= (SIM_SCGC4_UART0_MASK);
PORTA_PCR14 = PORT_PCR_MUX(3); //TX 0
PORTA_PCR15 = PORT_PCR_MUX(3); //RX 0
UART_C2_REG(UART0_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);
/* Configure the UART for 8-bit mode, no parity */
/* We need all default settings, so entire register is cleared */
UART_C1_REG(UART0_BASE_PTR) = 0;
/* Calculate baud settings */
ubd = (uint_16)((sysclk*1000)/(baud0 * 16));
/* Save off the current value of the UARTx_BDH except for the SBR */
temp0 = UART_BDH_REG(UART0_BASE_PTR) & ~(UART_BDH_SBR(0x1F));
UART_BDH_REG(UART0_BASE_PTR) = temp0 | UART_BDH_SBR(((ubd & 0x1F00) >> 8));
UART_BDL_REG(UART0_BASE_PTR) = (uint_8)(ubd & UART_BDL_SBR_MASK);
/* Determine if a fractional divider is needed to get closer to the baud rate */
brfa = (((sysclk*32000)/(baud0 * 16)) - (ubd * 32));
/* Save off the current value of the UARTx_C4 register except for the BRFA */
temp0 = UART_C4_REG(UART0_BASE_PTR) & ~(UART_C4_BRFA(0x1F));
UART_C4_REG(UART0_BASE_PTR) = temp0 | UART_C4_BRFA(brfa);
/* Enable receiver */
UART_C2_REG(UART0_BASE_PTR) |= ( UART_C2_RE_MASK | UART_C2_TE_MASK);
// configure ISR - UART 0 IRQ - 45
NVICICPR1 |= (1<<13); //45 MOD 32
NVICISER1 |= (1<<13);
NVICIP45 = 0x30; // priority 3. out of 15
Isr_InitIsr(INT_UART0_RX_TX, Uart_RxTx0_Isr);
}
Here is the Isr_InitIsr function:
void Isr_InitIsr(_mqx_uint isr, void (_CODE_PTR_ isr_func)(pointer))
{
MY_ISR_STRUCT_PTR isr_ptr;
isr_ptr = _mem_alloc_zero((_mem_size)sizeof(MY_ISR_STRUCT));
isr_ptr->TICK_COUNT = 0;
isr_ptr->OLD_ISR_DATA = _int_get_isr_data(isr);
isr_ptr->OLD_ISR = _int_get_isr(isr);
_int_install_isr(isr, isr_func, isr_ptr);
}
Solved! Go to Solution.
here is the solution:
void Uart_InitUart(void){ uint_32 ubd0,ubd1,ubd3,temp0,temp1,temp3,brfa; uint_32 sysclk = BSP_SYSTEM_CLOCK,busclk = BSP_BUS_CLOCK, baud0 = 115200, baud13 = 57600; //UART configuration SIM_SCGC4 |= (SIM_SCGC4_UART0_MASK | SIM_SCGC4_UART1_MASK | SIM_SCGC4_UART3_MASK); PORTA_PCR14 = PORT_PCR_MUX(3); //TX 0 PORTA_PCR15 = PORT_PCR_MUX(3); //RX 0 PORTC_PCR4 = PORT_PCR_MUX(3); //TX 1 PORTC_PCR3 = PORT_PCR_MUX(3); //RX 1 PORTB_PCR11 = PORT_PCR_MUX(3); //TX 3 PORTB_PCR10 = PORT_PCR_MUX(3); //RX 3 UART_C2_REG(UART0_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK); UART_C2_REG(UART1_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK); UART_C2_REG(UART3_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK); /* Configure the UART for 8-bit mode, no parity */ /* We need all default settings, so entire register is cleared */ UART_C1_REG(UART0_BASE_PTR) = 0; UART_C1_REG(UART1_BASE_PTR) = 0; UART_C1_REG(UART3_BASE_PTR) = 0; /* Calculate baud settings */ //ubd = (uint_32)((sysclk*1000)/(baud0 * 16)); ubd0 = (sysclk + 8 * baud0)/(16 * baud0); ubd1 = (sysclk + 8 * baud13)/(16 * baud13); ubd3 = (busclk + 8 * baud13)/(16 * baud13); /* Save off the current value of the UARTx_BDH except for the SBR */ temp0 = UART_BDH_REG(UART0_BASE_PTR) & ~(UART_BDH_SBR(0x1F)); temp1 = UART_BDH_REG(UART1_BASE_PTR) & ~(UART_BDH_SBR(0x1F)); temp3 = UART_BDH_REG(UART3_BASE_PTR) & ~(UART_BDH_SBR(0x1F)); UART_BDH_REG(UART0_BASE_PTR) = temp0 | UART_BDH_SBR(((ubd0 & 0x1F00) >> 8)); UART_BDH_REG(UART1_BASE_PTR) = temp1 | UART_BDH_SBR(((ubd1 & 0x1F00) >> 8)); UART_BDH_REG(UART3_BASE_PTR) = temp3 | UART_BDH_SBR(((ubd3 & 0x1F00) >> 8)); UART_BDL_REG(UART0_BASE_PTR) = (uint_8)(ubd0 & UART_BDL_SBR_MASK); UART_BDL_REG(UART1_BASE_PTR) = (uint_8)(ubd1 & UART_BDL_SBR_MASK); UART_BDL_REG(UART3_BASE_PTR) = (uint_8)(ubd3 & UART_BDL_SBR_MASK); /* Determine if a fractional divider is needed to get closer to the baud rate */ //brfa = (((sysclk*32000)/(baud0 * 16)) - (ubd * 32)); /* Save off the current value of the UARTx_C4 register except for the BRFA */ //temp0 = UART_C4_REG(UART0_BASE_PTR) & ~(UART_C4_BRFA(0x1F)); //temp1 = UART_C4_REG(UART1_BASE_PTR) & ~(UART_C4_BRFA(0x1F)); //UART_C4_REG(UART0_BASE_PTR) = temp0 | UART_C4_BRFA(brfa); //UART_C4_REG(UART0_BASE_PTR) = temp1 | UART_C4_BRFA(brfa); Isr_InitIsr(INT_UART0_RX_TX, Uart_RxTx0_Isr); Isr_InitIsr(INT_UART1_RX_TX, Uart_RxTx1_Isr); Isr_InitIsr(INT_UART3_RX_TX, Uart_RxTx3_Isr); // configure ISR - UART 0 IRQ - 45 NVICICPR1 |= (1<<13); //45 MOD 32 NVICISER1 |= (1<<13); NVICIP45 = 0x30; // priority 3. out of 15 // configure ISR - UART 1 IRQ - 47 NVICICPR1 |= (1<<15); //47 MOD 32 NVICISER1 |= (1<<15); NVICIP47 = 0x30; // priority 3. out of 15 // configure ISR - UART 3 IRQ - 51 NVICICPR1 |= (1<<19); //51 MOD 32 NVICISER1 |= (1<<19); NVICIP51 = 0x30; // priority 3. out of 15 // clear ISR flags temp0 = UART_S1_REG(UART0_BASE_PTR); temp1 = UART_S1_REG(UART1_BASE_PTR); temp3 = UART_S1_REG(UART3_BASE_PTR); /* Enable receiver */ UART_C2_REG(UART0_BASE_PTR) |= ( UART_C2_RE_MASK | UART_C2_TE_MASK | UART_C2_RIE_MASK | UART_C2_TIE_MASK); UART_C2_REG(UART1_BASE_PTR) |= ( UART_C2_RE_MASK | UART_C2_TE_MASK | UART_C2_RIE_MASK | UART_C2_TIE_MASK); UART_C2_REG(UART3_BASE_PTR) |= ( UART_C2_RE_MASK | UART_C2_TE_MASK | UART_C2_RIE_MASK | UART_C2_TIE_MASK); }
void Isr_InitIsr(_mqx_uint isr, void (_CODE_PTR_ isr_func)(pointer)){ MY_ISR_STRUCT_PTR isr_ptr; isr_ptr = _mem_alloc_zero((_mem_size)sizeof(MY_ISR_STRUCT)); isr_ptr->TICK_COUNT = 0; isr_ptr->OLD_ISR_DATA = _int_get_isr_data(isr); isr_ptr->OLD_ISR = _int_get_isr(isr); _int_install_isr(isr, isr_func, isr_ptr);}
void Uart_RxTx0_Isr(pointer user_isr_ptr){ MY_ISR_STRUCT_PTR isr_ptr; uint_16 temp; isr_ptr = (MY_ISR_STRUCT_PTR)user_isr_ptr; isr_ptr->TICK_COUNT++; // receive routine temp = UART_S1_REG(UART0_BASE_PTR); if (temp & UART_S1_RDRF_MASK) { if (m_rx0Len < UART_BUF) rx0Buf[m_rx0Len++] = UART_D_REG(UART0_BASE_PTR); } // transmit routine else if (temp & UART_S1_TDRE_MASK) { if ((m_tx0Sent < m_tx0Len) && (m_tx0Sent < UART_BUF)) { UART_D_REG(UART0_BASE_PTR) = tx0Buf[m_tx0Sent++]; } else { // stop transmission UART_C2_REG(UART0_BASE_PTR) &= ~(UART_C2_TIE_MASK); } }}
here is the solution:
void Uart_InitUart(void){ uint_32 ubd0,ubd1,ubd3,temp0,temp1,temp3,brfa; uint_32 sysclk = BSP_SYSTEM_CLOCK,busclk = BSP_BUS_CLOCK, baud0 = 115200, baud13 = 57600; //UART configuration SIM_SCGC4 |= (SIM_SCGC4_UART0_MASK | SIM_SCGC4_UART1_MASK | SIM_SCGC4_UART3_MASK); PORTA_PCR14 = PORT_PCR_MUX(3); //TX 0 PORTA_PCR15 = PORT_PCR_MUX(3); //RX 0 PORTC_PCR4 = PORT_PCR_MUX(3); //TX 1 PORTC_PCR3 = PORT_PCR_MUX(3); //RX 1 PORTB_PCR11 = PORT_PCR_MUX(3); //TX 3 PORTB_PCR10 = PORT_PCR_MUX(3); //RX 3 UART_C2_REG(UART0_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK); UART_C2_REG(UART1_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK); UART_C2_REG(UART3_BASE_PTR) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK); /* Configure the UART for 8-bit mode, no parity */ /* We need all default settings, so entire register is cleared */ UART_C1_REG(UART0_BASE_PTR) = 0; UART_C1_REG(UART1_BASE_PTR) = 0; UART_C1_REG(UART3_BASE_PTR) = 0; /* Calculate baud settings */ //ubd = (uint_32)((sysclk*1000)/(baud0 * 16)); ubd0 = (sysclk + 8 * baud0)/(16 * baud0); ubd1 = (sysclk + 8 * baud13)/(16 * baud13); ubd3 = (busclk + 8 * baud13)/(16 * baud13); /* Save off the current value of the UARTx_BDH except for the SBR */ temp0 = UART_BDH_REG(UART0_BASE_PTR) & ~(UART_BDH_SBR(0x1F)); temp1 = UART_BDH_REG(UART1_BASE_PTR) & ~(UART_BDH_SBR(0x1F)); temp3 = UART_BDH_REG(UART3_BASE_PTR) & ~(UART_BDH_SBR(0x1F)); UART_BDH_REG(UART0_BASE_PTR) = temp0 | UART_BDH_SBR(((ubd0 & 0x1F00) >> 8)); UART_BDH_REG(UART1_BASE_PTR) = temp1 | UART_BDH_SBR(((ubd1 & 0x1F00) >> 8)); UART_BDH_REG(UART3_BASE_PTR) = temp3 | UART_BDH_SBR(((ubd3 & 0x1F00) >> 8)); UART_BDL_REG(UART0_BASE_PTR) = (uint_8)(ubd0 & UART_BDL_SBR_MASK); UART_BDL_REG(UART1_BASE_PTR) = (uint_8)(ubd1 & UART_BDL_SBR_MASK); UART_BDL_REG(UART3_BASE_PTR) = (uint_8)(ubd3 & UART_BDL_SBR_MASK); /* Determine if a fractional divider is needed to get closer to the baud rate */ //brfa = (((sysclk*32000)/(baud0 * 16)) - (ubd * 32)); /* Save off the current value of the UARTx_C4 register except for the BRFA */ //temp0 = UART_C4_REG(UART0_BASE_PTR) & ~(UART_C4_BRFA(0x1F)); //temp1 = UART_C4_REG(UART1_BASE_PTR) & ~(UART_C4_BRFA(0x1F)); //UART_C4_REG(UART0_BASE_PTR) = temp0 | UART_C4_BRFA(brfa); //UART_C4_REG(UART0_BASE_PTR) = temp1 | UART_C4_BRFA(brfa); Isr_InitIsr(INT_UART0_RX_TX, Uart_RxTx0_Isr); Isr_InitIsr(INT_UART1_RX_TX, Uart_RxTx1_Isr); Isr_InitIsr(INT_UART3_RX_TX, Uart_RxTx3_Isr); // configure ISR - UART 0 IRQ - 45 NVICICPR1 |= (1<<13); //45 MOD 32 NVICISER1 |= (1<<13); NVICIP45 = 0x30; // priority 3. out of 15 // configure ISR - UART 1 IRQ - 47 NVICICPR1 |= (1<<15); //47 MOD 32 NVICISER1 |= (1<<15); NVICIP47 = 0x30; // priority 3. out of 15 // configure ISR - UART 3 IRQ - 51 NVICICPR1 |= (1<<19); //51 MOD 32 NVICISER1 |= (1<<19); NVICIP51 = 0x30; // priority 3. out of 15 // clear ISR flags temp0 = UART_S1_REG(UART0_BASE_PTR); temp1 = UART_S1_REG(UART1_BASE_PTR); temp3 = UART_S1_REG(UART3_BASE_PTR); /* Enable receiver */ UART_C2_REG(UART0_BASE_PTR) |= ( UART_C2_RE_MASK | UART_C2_TE_MASK | UART_C2_RIE_MASK | UART_C2_TIE_MASK); UART_C2_REG(UART1_BASE_PTR) |= ( UART_C2_RE_MASK | UART_C2_TE_MASK | UART_C2_RIE_MASK | UART_C2_TIE_MASK); UART_C2_REG(UART3_BASE_PTR) |= ( UART_C2_RE_MASK | UART_C2_TE_MASK | UART_C2_RIE_MASK | UART_C2_TIE_MASK); }
void Isr_InitIsr(_mqx_uint isr, void (_CODE_PTR_ isr_func)(pointer)){ MY_ISR_STRUCT_PTR isr_ptr; isr_ptr = _mem_alloc_zero((_mem_size)sizeof(MY_ISR_STRUCT)); isr_ptr->TICK_COUNT = 0; isr_ptr->OLD_ISR_DATA = _int_get_isr_data(isr); isr_ptr->OLD_ISR = _int_get_isr(isr); _int_install_isr(isr, isr_func, isr_ptr);}
void Uart_RxTx0_Isr(pointer user_isr_ptr){ MY_ISR_STRUCT_PTR isr_ptr; uint_16 temp; isr_ptr = (MY_ISR_STRUCT_PTR)user_isr_ptr; isr_ptr->TICK_COUNT++; // receive routine temp = UART_S1_REG(UART0_BASE_PTR); if (temp & UART_S1_RDRF_MASK) { if (m_rx0Len < UART_BUF) rx0Buf[m_rx0Len++] = UART_D_REG(UART0_BASE_PTR); } // transmit routine else if (temp & UART_S1_TDRE_MASK) { if ((m_tx0Sent < m_tx0Len) && (m_tx0Sent < UART_BUF)) { UART_D_REG(UART0_BASE_PTR) = tx0Buf[m_tx0Sent++]; } else { // stop transmission UART_C2_REG(UART0_BASE_PTR) &= ~(UART_C2_TIE_MASK); } }}
HI
I noticed in the isr you wrote above you are using a uint16 temp var to read the S1 register. Does this have any effect since the UART regs are all 8 bit?
thanks~
When Initializing I wrote :
NVICIP45 = 0x30; // priority 3. out of 15
this turn to be interfering with the MQX kernal , changing it to 10 , (0xA0) solved the issue.