Shop OBEX P1 Docs P2 Docs Learn Events
RFID Card Reader Serial 28140 UART to MSP430 Help! — Parallax Forums

RFID Card Reader Serial 28140 UART to MSP430 Help!

Terran910Terran910 Posts: 1
edited 2014-11-17 09:48 in Accessories
Does anyone have any example code for reading from the Parallax RFID Card Reader?
I'm not sure what I'm doing wrong, but I know the baud rate has to be 2400.
I worked off an example msp430 uart code, but I see nothing in the receive buffer.
#include <msp430.h>

char RxByte;
char RxData[256];
char TxByte;
volatile unsigned int i;


int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  if (CALBC1_8MHZ==0xFF)                    // If calibration constant erased
  {
    while(1);                               // do not load, trap CPU!!
  }


  DCOCTL = 0;                               // Select lowest DCOx and MODx settings
  BCSCTL1 = DIVA0;
  BCSCTL1 = CALBC1_8MHZ;
  DCOCTL = CALDCO_8MHZ;                     // Load 8MHz constants
  P1OUT &= ~0x01;                           // Clear P1.0
  P1DIR |= 0x01;                            // P1.0 output
  P3SEL |= 0x30;                            // Use P3.4/P3.5 for USCI_A0
  UCA0CTL1 |= UCSWRST;                      // Set SW Reset
  UCA0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
  UCA0BR0 = 0x05;                           // 8MHz/3333=2.4KHz
  UCA0BR1 = 0x0D;                            
  UCA0MCTL = UCBRF_1 + UCOS16;              // Set 1st stage modulator to 1
                                            // 16-times oversampling mode
  UCA0IRTCTL = UCIRTXPL2 + UCIRTXPL0 + UCIRTXCLK + UCIREN;
                                            // Pulse length = 6 half clock cyc
                                            // Enable BITCLK16, IrDA enc/dec
  UCA0CTL1 &= ~UCSWRST;                     // Resume operation


  TxByte = 0x00;                            // TX data and pointer, 8-bit


  while (1)
  {
    for (i = 1000; i; i--);                 // Small delay
//    while (!(IFG2 & UCA0TXIFG));            // USCI_A0 TX buffer ready?
//    UCA0TXBUF = TxByte;                     // TX character


    __disable_interrupt();
    IE2 |= UCA0RXIE;                        // Enable RX int
    __bis_SR_register(CPUOFF + GIE);        // Enter LPM0 w/ interrupts


//    RxByte = UCA0RXBUF;                       // Get RXed character
    if (RxByte == 0x0A)                   // RX OK?
    {
        RxData[0] = RxByte;                // Store RXed character in RAM
      P1OUT |= 0x01;                        // LED P1.0 on
    }
    if (RxByte == 0x0D)                   // RX OK?
    {
        RxData[1] = RxByte;                // Store RXed character in RAM
      P1OUT |= 0x01;                        // LED P1.0 on
    }
    TxByte++;                               // Next character to TX
  }
}


#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCIAB0RX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCIAB0RX_ISR (void)
#else
#error Compiler not supported!
#endif
{
  RxByte = UCA0RXBUF;                       // Get RXed character
  IE2 &= ~UCA0RXIE;                         // Disable RX int
  __bic_SR_register_on_exit(CPUOFF);        // Exit LPM0
}

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-09-18 10:35
    I apologize, I am not a C programmer, however I did want to ask if you're enabling the RFID Reader? The /ENABLE pin must be brought low for the RFID Reader to serially transmit the tag ID out through the SOUT pin. You will know visually if it is enabled by the LED turning Red instead of Green. Once the data data has been received the /ENABLE line is typically released (internally pulled high) by making the pin an input and the LED will turn Green. After a second (or some delay) you bring the /ENABLE line low again to read the next tag.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2014-11-14 21:36
    Was this ever resolved?
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-11-17 09:48
    I think Chris' assumption may be correct. I don't see anything in the code that might toggle the /ENABLE pin. I don't know this chip, but the code presented appears to simply read whatever is coming into the hardware serial.
Sign In or Register to comment.