i want to use 2-wire to do the communication of two nrf24le1. one is the master, another is slave. I don't know how to set up the master and slave. Is it the code shown below correct? P0.1 and P0.2 connect with two LED.
master
void I2C_ISP(void) interrupt INTERRUPT_SERIAL
{
P02 = !P02;
}
void main(void)
{
uint8_t a[1];
hal_w2_configure_master(HAL_W2_400KHZ);
IEN1 |= 0x04;
INTEXP |= 0x04;
delay_ms(1);
EA = 1U;
P0DIR = 0x00;
a[0] = 0xff;
while(1)
{
hal_w2_write(0x20,a,1);
delay_ms(1000);
a[0] = !a[0];
P01 = !P01;
}
}
slave
void I2C_ISP(void) interrupt INTERRUPT_SERIAL
{
P02 = !P02;
i2c_recive = HAL_W2_READ();
}
void main(void)
{
hal_w2_enable(true);
hal_w2_set_clk_freq(HAL_W2_400KHZ);
hal_w2_set_op_mode(HAL_W2_SLAVE);
hal_w2_all_irq_enable(true);
hal_w2_set_slave_address(0x20);
hal_w2_alter_clock(true);
IEN1 |= 0x04;
INTEXP |= 0x04;
delay_ms(1);
EA = 1U;
P0DIR = 0x00;
while(1)
{
delay_ms(1000);
P01 = !P01;
}
}