Here are my functions which i wrote for reading / writing the i2c slave device ( after reading reference manual (nrf51422) . Unfortunately they are not working. Plz help me with the code.
void twi_init_slz(void )
{
(*(unsigned volatile int *)0x040003500)= 0x00; //Disable SPI AND TWI
//(*(unsigned volatile int *)0x040003200)= 0x00; //SHORTCUT REGISTER
(*(unsigned volatile int *)0x040003508)= 30U; //PSELSCL
(*(unsigned volatile int *)0x04000350C)= 7U; //PSELSDA
(*(unsigned volatile int *)0x050000518)= ~((1UL<<30)|(1UL<<7));
(*(unsigned volatile int *)0x050000778)= (6UL<<8)|(3UL<<2); //set pin
(*(unsigned volatile int *)0x05000071C)= (6UL<<8)|(3UL<<2); //set pin
//(*(unsigned volatile int *)0x040003300)= (1UL<<2)|(1UL<<7)|(1UL<<7)|(1UL<<9)|(1UL<<14); //INTEN
(*(unsigned volatile int *)0x040003304)= (1UL<<2)|(1UL<<7)|(1UL<<7)|(1UL<<9)|(1UL<<14); //INTENSET
(*(unsigned volatile int *)0x040003524)= 0x01980000; //FREQUENCY
(*(unsigned volatile int *)0x040003124)= 1UL; //ERROR
(*(unsigned volatile int *)0x040003500)= 0x05; //ENABLE TWI
}
void set_address_twi_slz(int address)
{
(*(unsigned volatile int *)0x040003588)= address; //I2C ADDRESS
}
int read_twi_slz(void)
{
nrf_delay_ms(10);
printf("In read\n");
//(*(unsigned volatile int *)0x40003588)|= 1UL;
(*(unsigned volatile int *)0x40003000)= 1; //STARTRX
nrf_delay_ms(10); while(!((*(unsigned volatile int *)0x40003108))); //wait for RXREADY EVENT
nrf_delay_ms(10);
int read_i2c_value = (*(unsigned volatile int *)0x40003518); //copying RX Register
nrf_delay_ms(10);
(*(unsigned volatile int *)0x40003014)= 1; //Stop
return read_i2c_value;
}
bool write_twi_slz(int data)
{
(*(unsigned volatile int *)0x40003008)=1;
(*(unsigned volatile int *)0x4000351C)=data;
int check =(*(unsigned volatile int *)0x04000351C);
if(check)
{
return 1; // successfully sent
}
else
{
return 0; //Sent error
}
}