...
sbit MFRC522_CS at LATC.B3;
sbit MFRC522_Rst at LATA.B0;
//sbit SoftSPI_SDO at LATC.B1;
//sbit SoftSPI_CLK at LATC.B2;
//sbit SoftSPI_SDI at LATC.B0;
sbit MFRC522_CS_Direction at TRISC3_Bit;
sbit MFRC522_Rst_Direction at TRISA0_Bit;
//sbit SoftSPI_SDO_Direction at TRISC1_Bit;
//sbit SoftSPI_CLK_Direction at TRISC2_Bit;
//sbit SoftSPI_SDI_Direction at TRISC0_Bit;
...
inside main
...
//Soft_SPI_Init();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
...
inside InitMCU
...
SSP1DATPPS = 0x10; // SDI en pin RC0
RC1PPS = 0x10; // SDO en pin RC1
RC2PPS = 0x0F; // SCK en pin RC2
...
static void MFRC522_Wr( char addr, char value )
{
MFRC522_CS = 0;
SPI1_Write( 0x00 );
SPI1_Write( ( addr << 1 ) & 0x7E );
SPI1_Write( value );
MFRC522_CS = 1;
}
static char MFRC522_Rd( char addr )
{
char value;
MFRC522_CS = 0;
SPI1_Write( (( addr << 1 ) & 0x7E) | 0x80 );
value = SPI1_Read( 0x00 );
MFRC522_CS = 1;
return value;
}