I am attempting to Bit-Bash a UART communication (the built in module doesn't work for my application) and am having problems achieving a baud rate of 250kbps.
My MSP430 is setup to run at 16MHz and the Timer is setup as follows:
/* Timer A4 - Tx */ TA4CTL &= ~0x3F7; TA4CTL |= TBSSEL__SMCLK; /* Choose SMCLK as clock source */ TA4CTL |= ID__1; /* Clock input divider - 1 */ TA4EX0 |= TBIDEX__1; /* Clock input divider expansion - 1 */ TA4CTL |= MC__UP; /* Mode select - Up Mode */ TA4CCR0 = 0U; /* Stop the Timer */ TA4CTL |= TBCLR; /* Timer_B clear */
When I want to start the timer I use the following to get the Timer to trigger every 4us:
/* Start transmission */ TA4CCTL0 |= CCIE ; /* Timer_A int enable */ TA4CCR0 = 64U;
When I only include a simple GPIO toggle in the interrupt, the output frequency can keep to 4us, however if I try to add more complexity into the interrupt, the fastest it can go is 5.5us, often as high as 6.5-9us.
I would like to implement the following interrupt:
main(void) { while(1) { while(uart_ctl.bit_index != uart_ctl.frame_bit_count); uart_ctl.bit_index = 0U; } } #pragma vector = TIMER4_A0_VECTOR __interrupt void Uart_tx_timer_isr(void) { P2OUT = uart_ctl.tx_buffer[uart_ctl.bit_index]; /* Set state of Port 2 to the values in transmit buffer */ uart_ctl.bit_index += 1U; /* Increment bit index */ }
where each element of uart_ctl.tx_buffer contains the state of each pin on Port 2, where BIT0 (Tx pin) changes depending on each bit in the message. Both the uart.ctl struct, and the interrupt, are in RAM. I am using Compiler version v21.6.9.
Is it actually possible to run the interrupt every 4us while doing this operation? To me it doesn't seems terribly complex and should easily be able to manage it in 64 clock cycles, am I wrong in this assumption? If it is possible, are there any registers I may have not set up, or set up incorrectly?
Thanks in advance,
Joe