2016-12-20 04:35 AM
2016-12-20 05:22 AM
Receiver does not work.
Make sure your connections are OK. Read back the GPIO registers in a debugger and verify their content is what you intended.
[EDIT]
I2C_CR2:
SADD[7:1]: Slave address bit 7:1 (master mode)
In 7-bit addressing mode (ADD10 = 0):These bits should be written with the 7-bit slave address to be sentI2C_OAR1:
Bits 7:1 OA1[7:1]: Interface address
Bits 7:1 of addressWell, the latter is just another incarnation of the 'I don't understand the 7-bit address from I2C specification'. OA1 should contain the 7-bit address, ergo, drop the shift in
I2C1->OAR1 |= (0x10<<1); // set own address
JW
PS.
2016-12-20 07:48 AM
Right, so the address value has to be in the range between 0x08 and 0x77
Also, the I2C_write function should have address shifted to the left once as well as the bit 0 has to do with 10-bit interface
I2C1->CR2 = I2C_CR2_RELOAD | (uint32_t) (1 << 16) | (uint32_t) (address << 1);
I have changed that, but my code still does not work
:(
2016-12-20 08:53 AM
The address both in OAR and CR2 has the same structure, so either shift both (treating them as 7-bit address as per I2C spec) or none (treating them as the 'customary' 8-bit address).
If you have both shifted, then again, double-check the connections and the macros you've used in the slave code.
JW
2016-12-20 09:18 AM
The connections are fine as I'm able to generate some transmit messages from the slave MCU. I did not include these parts of the code into the message, but the MCU does work and it works as I2C master/slave on its own as well, so I can talk to other ICs and etc..
2016-12-20 09:27 AM
> The connections are fine
OK, but I also asked you to check the GPIO setup (and possibly also I2C's) by reading back the registers' content.
> I did not include these parts of the code into the message
Never do anything else than copy/paste. You are asking for help - how do you know the problem is not in the part you've cut out?
---
Create a minimal slave - basically the same what you've posted above - and post it in its entirety, together with the GPIO and I2C registers content and the LA trace.
JW
2016-12-21 04:07 AM
Sorry, I think you misunderstood me. I did not mean that there are other parts of the code that are being executed. What I meant is that I tried using Slave MCU for communication with other ICs on the board and it was fine. I do not execute anything other than what I've shared. I can share 'Slave MCU to IC' code as well, but to me it looks like a different subject, since there is no correlation with MCU-master-MCU-slave communications.
Yes, I have checked all GPIOs in a debugger as well as the steps that the program takes. All values are OK, I have got AF function set for PB7&8 on master MCU. On slave MCU it is PB8&9. They are open drain, no pull up, low speed. MODER is set correctly.
All steps in a debugger do work except that on the slave MCU when the code checks RXNE register, it finds it empty and exits the loop. In its turn, the master MCU puts data into TXDR register and then receives a NACK.
I have now tried running master MCU code on slave MCU as you suggested - the result is the same. I have also tried to swap MCU functions completely, basically to turn a slave MCU into a master and a master into a slave. Same problem
:(
Many thanks!
2016-12-21 08:43 AM
Create a minimal slave - basically the same what you've posted above - and post it in its entirety, together with the GPIO and I2C registers content and the LA trace.
(I know I repeat myself)
JW