We are trying to connect an EM-18 RFID Reader Module to our msp430FR4133 via UART serial connection.
However, interrupts involving the UCA0IFG flag do not seem to be triggering as the flag doesn't get set when we scan our rfid card.
The rfid module is connected from its TX pin to the MCUs RX pin.
We can confirm that it is connected properly because if we open the Putty terminal and connect TX to TX we can see the correct rfid card code displayed on the terminal after a scan.
We believe this to be an issue with our code.
The question is, why is the UCA0IFG flag not getting set?
Here's the code bellow:
#include <msp430.h> #include "driverlib/MSP430FR2xx_4xx/eusci_a_uart.h" #include "Board.h" #define GPIO_PIN0 (0x0001) #define GPIO_PIN1 (0x0002) #define GPIO_PORT_P1 1 #define GPIO_PRIMARY_MODULE_FUNCTION (0x01) #define CS_ACLK 0x01 #define CS_MCLK 0x02 #define CS_SMCLK 0x04 #define CS_REFOCLK_SELECT SELMS__REFOCLK #define CS_DCOCLKDIV_SELECT SELMS__DCOCLKDIV #define CS_CLOCK_DIVIDER_1 DIVM__1 void conditionalBlink() { // to activate previously configured port settings P4DIR |= 0x01; // Set P4.0 to output direction for(;;) { volatile unsigned int i; // volatile to prevent optimization P4OUT ^= 0x01; // Toggle P4.0 using exclusive-OR i = 10000; // SW Delay do i--; while(i != 0); } } #if defined(_TI_COMPILER_VERSION_) || defined(_IAR_SYSTEMS_ICC_) #pragma vector=USCI_A0_VECTOR __interrupt void USCI_A0_ISR(void) #elif defined(_GNUC_) void __attribute__((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR(void) #error Compiler Not Supported! #endif { switch (__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG)) { case USCI_NONE: break; case USCI_UART_UCRXIFG: conditionalBlink(); break; case USCI_UART_UCTXIFG: break; case USCI_UART_UCSTTIFG: break; case USCI_UART_UCTXCPTIFG: break; } } void Init_UART(void) { //Set ACLK = REFOCLK with clock divider of 1 CS_initClockSignal(CS_ACLK,CS_REFOCLK_SELECT,CS_CLOCK_DIVIDER_1); //Set SMCLK = DCO with frequency divider of 1 CS_initClockSignal(CS_SMCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1); //Set MCLK = DCO with frequency divider of 1 CS_initClockSignal(CS_MCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1); //Configure UART pins, which maps them to a COM port over the USB cable //Set P1.0 and P1.1 as Secondary Module Function Input. //GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION); //GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1, GPIO_PIN0, GPIO_PRIMARY_MODULE_FUNCTION); //Configure UART pins GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_UCA0TXD, GPIO_PIN_UCA0TXD, GPIO_FUNCTION_UCA0TXD ); GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_UCA0RXD, GPIO_PIN_UCA0RXD, GPIO_FUNCTION_UCA0RXD ); /* * Disable the GPIO power-on default high-impedance mode to activate * previously configured port settings */ PMM_unlockLPM5(); /* * UART Configuration Parameter. These are the configuration parameters to * make the eUSCI A UART module to operate with a 9600 baud rate. These * values were calculated using the online calculator that TI provides at: * software-dl.ti.com/.../index.html */ //SMCLK = 1MHz, Baudrate = 9600 //UCBRx = 6, UCBRFx = 8, UCBRSx = 17, UCOS16 = 1 EUSCI_A_UART_initParam param = {0}; param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK; param.clockPrescalar = 6; param.firstModReg = 8; param.secondModReg = 17; param.parity = EUSCI_A_UART_NO_PARITY; param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST; param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT; param.uartMode = EUSCI_A_UART_MODE; param.overSampling = 1; if(STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, ¶m)) { return; } EUSCI_A_UART_enable(EUSCI_A0_BASE); EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT); // Enable EUSCI_A0 RX interrupt EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT); EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT); } int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer Init_UART(); __enable_interrupt(); while (1) { __bis_SR_register(LPM0_bits + GIE); } return 0; }
Thanks for your help !!