This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Howdy,
I am working with a proprietary communication protocol similar to I2C and SPI but different enough to where I can't use the CCS libraries, so I am trying to bit bang it using an MSP430. Currently I have P1.4 using TA0.3 to output my clock signal (500 kHz PWM) and I want to use a GPIO to send data.
My end goal is to use the Timer0 A0 interrupt so that a bit will shift out every rising edge or high state of the PWM. As a test I just wanted to flip the bit every time the interrupt is called but the GPIO is switching at around 37.7 kHz, much slower than expected. The minimum I can run the comm is 100kHz. Are interrupts just really slow, or am I missing something fundamental in the code?
#include <msp430.h> void PWMinit(void); int main(void) { unsigned int i; WDTCTL = WDTPW + WDTHOLD; // Stop WDT PWMinit(); dataformation(); __bis_SR_register(GIE); // enable interrupts while (1) { } } void PWMinit(void){ P1DIR |= BIT6; // P1.6 interrupt debug P1DIR |= BIT4; //P1.4 output P1SEL |= BIT4; //P1.4 to TA0.3 TA0CCR0 = 1; // PWM frequency = 1MHz/(TA0CCR0+1) = 500 kHz TA0CCTL3 = OUTMOD_7; // CCR3 reset/set TA0CCR3 = 1; // CCR3 PWM duty cycle Ton = (TB0CCR1)/1MHz TA0CCTL0 = CCIE; // CCR0 interrupt enabled TA0CTL = TASSEL__SMCLK | MC__UP | TACLR; // SMCLK, up mode, clear TAR } // Timer0 A0 interrupt service routine #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER0_A0_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) TIMER0_A0_ISR (void) #else #error Compiler not supported! #endif { P1OUT ^= BIT6; // Toggle P1.0 }
**Attention** This is a public forum