Hi all,
STM32F103 as an I2C master works as a charm.
Now I want to use the STM32 @72MHz as an I2C slave connected to an AVR M328 as master. There's an SSD1306 in the circuit also. SCL freq = 100KHz. Systick interrupt occurs each 1ms.
STM32 pseudo code:
Initialize OLED and display a greeting
Wait forever:
If a byte is received display it
AT_M328 pseudo code:
Init TWI
Do forever:
send start condition + slave address
send 4 bytes
send stop condition
Full code attached.
Slave address = 0x30 in 7bit format.
bytes to send: 0xC0, 0xC1, 0xC2, 0xC3
If the NOSTRETCH bit in I2C-CR1 is cleared The STM32 ACKs the address but the M328 don't send any byte.
If the NOSTRETCH is set The STM32 ACKs the address and the 1st byte so now the M328 can send one byte only.
I verified this with a logic analyzer, SCL is kept LOW. It seems that the STM32 stretches SCL low (photos attached).
Also the adress matching event or byte received interrupts never occur.
Of course I've enabled the I2C event interrupt (IRQn = 31 )in the NVIC and written the corresponding handler.
The event interrupt works. When I enable it after initializing the module the handler is executed.
The M328 code is tested with an other slave and it works perfectly.
I tried with no success:
- Disabling the Systick interrupt.
- Lowering SCL freq to 50KHz
- Reseting the I2C module using RCC_APB1RSTR.
- Drinking a beer !!
How to configure SDA and SCL in slave mode? I used alternate function output open-drain @ 50MHz.
Is pull-up resistors mandatory for the STM32's SCL and SDA? The circuit contains an SSD1306 which have pull-ups, also the M328 has it's internal pull-ups on PC4 and PC5 enabled.
Please, What I'm missing??
Thanks