Hi there
I try to establish I2C coms among an STM32F303 configured as master and an Argon as a slave.
Both codes for master and slave are simple and compilled-flashed successfully, without errors. The STM32 transmits START-Address 0x04 and if receives ACK from Argon transmits Data = 0x00, then Data increments by 1 and so on.
The Argon doesn’t return the ACK, never.
My hardware is correct and I have checked both the SDA and SCL lines with the scope and are working just fine. I also confirmed that the state of SDA after START-Address is always high and that means there is no ACK.
I can also confirm that from the master side, the Baud Rate is 100KHz, the SMBUS and Slew Rate control is disabled, and I have tried either the Stop Delay of 10ms enabled or disabled with the same result.
Here the code of master STM32 (obtained with Flow Code):
int main()
{
SystemClocksSetup();
HAL_Init();
// Enable ports ABCDEF
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
// Value = Data to transmit
// Calculation:
// Value = 0x00
FCV_VALUE = 0x00;
// Initialize Master
// Call Component Macro: I2C_Master1::Initialise()
FCD_005f1_I2C_Master1__Initialise();
// Loop
// Loop: While 1
while (1)
{
// Delay
// Delay: 1000 ms
FCI_DELAYINT_MS(1000);
// Master sends Start
// Call Component Macro: I2C_Master1::Start()
FCD_005f1_I2C_Master1__Start();
// Master transmit address of Slave (0x04 for the instance)
// Call Component Macro: ACK=I2C_Master1::TransmitByte(0x04)
FCV_ACK = FCD_005f1_I2C_Master1__TransmitByte(0x04);
//Comment:
//If Slave receives its
//address, responds by
//transmitting ACK = 0.
// Decision
// Decision: ACK = 0?
if (FCV_ACK == 0)
{
// Output
// Output: 1 -> B0
FCP_SET(M, B, 0x00000001, 0, (1));
// Master transmits Data = Value
// Call Component Macro: ACK=I2C_Master1::TransmitByte(Value)
FCV_ACK = FCD_005f1_I2C_Master1__TransmitByte(FCV_VALUE);
} else {
// Output
// Output: 1 -> B6
FCP_SET(M, B, 0x00000040, 6, (1));
}
// Master sends Stop transmition
// Call Component Macro: I2C_Master1::Stop()
FCD_005f1_I2C_Master1__Stop();
// Calculation
// Calculation:
// Value = Value + 1
FCV_VALUE = FCV_VALUE + 1;
// Delay
// Delay: 20 ms
FCI_DELAYBYTE_MS(20);
// Output
// Output: 0 -> B6
FCP_SET(M, B, 0x00000040, 6, (0));
// Output
// Output: 0 -> B0
FCP_SET(M, B, 0x00000001, 0, (0));
}
mainendloop: goto mainendloop;
return 0;
}
Here is the code of slave Argon:
uint8_t data[8];
int idx;
void receiveEvent(int numOfBytes) {
idx = 0;
while (Wire.available()) {
data[idx++] = (uint8_t)Wire.read();
}
}
// setup() runs once, when the device is first turned on.
void setup() {
// Put initialization like pinMode and begin functions here.
pinMode(A0,OUTPUT);
digitalWrite(A0,LOW);
pinMode(A1,OUTPUT);
digitalWrite(A0,LOW);
pinMode(A2,OUTPUT);
digitalWrite(A2,LOW);
Serial.begin(9600);
Wire.begin(0x04);
Wire.onReceive(receiveEvent);
pinMode(D7,OUTPUT);
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
if (idx != 0) {
digitalWrite(D7,HIGH);
Serial.print("RX (");
Serial.print(idx);
Serial.print("): ");
for(int i=0;i<idx;i++) {
Serial.println(data[i],HEX);
}
idx = 0;
digitalWrite(D7,LOW);
}
}
Thanks for any help.