update to own SPI lib
This commit is contained in:
parent
305aacc83f
commit
977c26b2ca
40
Mfrc522.c
40
Mfrc522.c
@ -5,10 +5,12 @@
|
||||
Lightly modified by Frank Milburn
|
||||
Lightly modified by Roy Bakker C++ --> C
|
||||
Released into the public domain
|
||||
Lightly modified by Mats van Reenen: use other SPI interface
|
||||
*/
|
||||
|
||||
#include <Mfrc522.h>
|
||||
#include <SPI.h>
|
||||
//#include <SPI2.h>
|
||||
|
||||
void RC522_init(int chipSelectPin, int NRSTPD)
|
||||
{
|
||||
@ -46,12 +48,20 @@ void RC522_init(int chipSelectPin, int NRSTPD)
|
||||
*/
|
||||
void RC522_writeReg(unsigned char addr, unsigned char val)
|
||||
{
|
||||
P1OUT &= ~(_chipSelectPin);
|
||||
SPIInitSend(_chipSelectPin, SPI_Mode0, SPI_Clock_4MHz);
|
||||
|
||||
SPI_transfer((addr<<1)&0x7E);
|
||||
SPI_transfer(val);
|
||||
SPI_packet[3] = (addr<<1)&0x7E;
|
||||
SPI_packet[4] = val;
|
||||
SPI_packetC = 3;
|
||||
|
||||
SPISend();
|
||||
|
||||
// P1OUT &= ~(_chipSelectPin);
|
||||
|
||||
// SPI_transfer((addr<<1)&0x7E);
|
||||
// SPI_transfer(val);
|
||||
|
||||
P1OUT |= _chipSelectPin;
|
||||
// P1OUT |= _chipSelectPin;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -62,15 +72,25 @@ void RC522_writeReg(unsigned char addr, unsigned char val)
|
||||
*/
|
||||
unsigned char RC522_readReg(unsigned char addr)
|
||||
{
|
||||
unsigned char val;
|
||||
P1OUT &= ~(_chipSelectPin);
|
||||
SPIInitSend(_chipSelectPin, SPI_Mode0, SPI_Clock_4MHz);
|
||||
|
||||
SPI_transfer(((addr<<1)&0x7E) | 0x80);
|
||||
val = SPI_transfer(0x00);
|
||||
SPI_packet[3] = ((addr<<1)&0x7E) | 0x80;
|
||||
SPI_packet[4] = 0;
|
||||
SPI_packetC = 3;
|
||||
|
||||
SPISend();
|
||||
|
||||
return SPI_packet[4];
|
||||
|
||||
// unsigned char val;
|
||||
// P1OUT &= ~(_chipSelectPin);
|
||||
|
||||
// SPI_transfer(((addr<<1)&0x7E) | 0x80);
|
||||
// val = SPI_transfer(0x00);
|
||||
|
||||
P1OUT |= _chipSelectPin;
|
||||
// P1OUT |= _chipSelectPin;
|
||||
|
||||
return val;
|
||||
// return val;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
38
SPI2.h
38
SPI2.h
@ -1,38 +0,0 @@
|
||||
#ifndef _SPI_H_INCLUDED
|
||||
#define _SPI_H_INCLUDED
|
||||
|
||||
#include <msp430.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
inline static void SPI_begin();
|
||||
inline static uint8_t SPI_transfer(uint8_t data);
|
||||
inline static void SPI_end();
|
||||
|
||||
void SPI_begin(void) {
|
||||
/* Configure P1.5, 1.6, 1.7 for SPI. */
|
||||
P1SEL |= (BIT5 | BIT6 | BIT7);
|
||||
P1SEL2 |= (BIT5 | BIT6 | BIT7);
|
||||
|
||||
/* Setup SPI on USCI B */
|
||||
UCB0CTL1 = (UCSSEL_2 | UCSWRST); // SMCLK + Reset
|
||||
UCB0CTL0 = (UCCKPL | UCMSB | UCMST | UCSYNC); // 3-pin, 8-bit SPI master
|
||||
UCB0BR0 = 8; // /8
|
||||
UCB0BR1 = 0; //
|
||||
|
||||
UCB0CTL1 &= ~UCSWRST; // release USCI for operation
|
||||
}
|
||||
|
||||
uint8_t SPI_transfer(uint8_t data) {
|
||||
UCB0TXBUF = data; // Setting TXBUF clears the TXIFG
|
||||
|
||||
while(UCB0STAT & UCBUSY); // wait for SPI TX/RX to finish
|
||||
|
||||
return UCB0RXBUF; // Reading clears RXIFG
|
||||
}
|
||||
|
||||
void SPI_end()
|
||||
{
|
||||
UCB0CTL1 |= UCSWRST; // Put USCI in reset mode
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user