2018-04-06 07:02 AM
Hi everyone,
I'm trying to create my own blocking I2C driver and want to split the usage up into a few primitive functions, e.g. for I2C Master Transmitter, the following functions apply:
bool i2c_start_write(uint8_t sla_adr);
bool i2c_wr_u8(uint8_t data);
bool i2c_stop(px_i2c_handle_t * handle);
In i2c_start_write() I do the following:
1. Wait until I2C_ISR_BUSY=0
2. I2C_CR2_SADD = sla_adr
3. I2C_CR2_RD_WRN = 0
4. I2C_CR2_RELOAD = 1
5. I2C_CR2_NBYTES = 0 (I do not know yet how many bytes will be needed to be transmitted)
6. I2C_CR2_START = 1 (to generate START condition and SLA+W)
7. Wait until I2C_CR2_START = 0
8. Check I2C_ISR_NACKF to verify that I2C slave ACK'd
In i2c_wr_u8() I do the following:
9. Check that I2C_ISR_BUSY=1
10. I2C_CR2_NBYTES = 1 (I want to transmit one byte)
11. Wait until I2C_ISR_TCR is set (??)
12. TXDR = data (??)
13. Wait until I2C_ISR_TCR is set(??)
At step 10 I can change I2C_CR2_NBYTES, but the I2C peripheral does not pick up this change and start the transmission sequence. Is there a way to 'kick-start' the RELOAD process?
Am I forced to load NBYTES before I begin the START condition?
Thanks in advance,
Pieter