BiNa2605
Full Member level 3
- Joined
- Sep 1, 2015
- Messages
- 179
- Helped
- 6
- Reputation
- 12
- Reaction score
- 4
- Trophy points
- 18
- Location
- VietNam
- Activity points
- 1,357
I want to interface with EEPROM of (sensor tag UHF RFID) using MCU Microchip by applying SPI. But I cannot write data into EEPROM of sensor tag. These are my code:
But it is not work. And then the datasheet and memory of this eeprom
Code:
#define SEN PORTC.B1
#define WRITE 0x0000
#define READ 0x4000
#define PAGE_WR 0x0800
unsigned int uiTemp=0;
//Write function for the SPI interface
void SL900A_Write(unsigned int uiMode, unsigned int uiAddress, unsigned char ucData){
SEN = 1; //Enable Slave select
delay_us(500); //SEN to first SCLK rising edge setup time
//Transmit 16 bit data
uiTemp = (uiMode&0xff00) | uiAddress;
SPI1_Write(uiTemp);
SPI1_Write(ucData); //Data need to transmit
delay_ms(1);
SEN = 0; //Stop
}
void main()
{
unsigned char ucwrData, ucMo;
unsigned int uiMo, uiAdd,i,uiTemp1;
//FOSC = 0b110; INTOSC oscillator
//OSCCON = 0b01011010; //Internal Oscillator 1Mhz --- SL900A -> 1.5v
//OSCCON = 0b01101010; //Internal Oscillator 4Mhz
OSCCON = 0b01110010; //Internal Oscillator 8Mhz
//OSCCON = 0b01111010; //Internal Oscillator 16Mhz
TRISC.B1 = 0; //RC1 output Select SPI
PORTC.B1 = 1;
TRISB.B4 = 0; //RB4 output test led
//SPI
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
//SPI1_Init();
//Choose MODE in here
uiMo = WRITE;
//uiAdd = 0x047E; //the last physical address of SL900A User_Memory
uiAdd = 0; //The first physical address of SL900A User_Memory
ucwrData = 0x01;
for (i=0;i<100;i++){
SL900A_Write(uiMo,uiAdd+i,ucwrData);
delay_ms(1);
}
while(1){
PORTB.B4 = 0;
//delay_ms(100);
//PORTB.B4 = 0;
//delay_ms(100);
}
}