Tool/software: Code Composer Studio
Hi
I wrote this program for communication between TI MSP430G2553 and NPX MFRC522 RFID reader.
I trying to read the Version of the ic (register adress 0x37) so i send over MOSI channel the address like datasheet instructions:
In the arduino version of mfrc522 library code, after sent the address have to sent a dummy byte. In this manner the after the ic had process the request it "shift" the required value in the master RX register (I think).
After the address was sent over the MOSI I recive in the RX register the value 0xFF (i think this is normal) but when I send the dummy byte (and I should be getting the value of the version register) i recive 0xFF again.
What's the problem? Thanks in advance
I attach the code below
#include <msp430.h>
#include <stdint.h>
#include <stdio.h>
volatile char received_ch = 0;
uint8_t SPI_write(uint8_t data){
//IFG2 &=~(UCA0RXIFG+UCA0TXIFG);
P1OUT &= (~BIT5); // Select Device
UCA0TXBUF = data; // setting TXBUF clears the TXIFG flag
while (!(IFG2 & UCA0RXIFG));
// wait for SPI TX/RX to finish
P1OUT |= BIT5;
return UCA0RXBUF;
}
#define SPI_read() (SPI_write(0x00)) // Read by sending a dummy byte
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1OUT |= BIT5;
P1DIR |= BIT5;
P1SEL = BIT1 | BIT2 | BIT4;
P1SEL2 = BIT1 | BIT2 | BIT4;
UCA0CTL1 = UCSWRST;
UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x02; // /2
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE;
SPI_write((0x37<<1) | 0x80);
//for(x = 2000; x > 0; x--);
int value = SPI_write(0);
}
