Question:
How do you access STM32 registers in Necto for example
Code: Select all
I2C1_CR2bits.SADD=0;
Now the issue
I noticed this when using Mikro C I found a Bug in the I2C libarary for STM32L4 family of products specifically STM32L462, STM32L432. The address of the slave device is corrupted if you try to access a second or third device on the same bus and therefore nothing works after the first transmission to the first device it seems like the address from the first device is not fully cleared in the library when accessing the second device or its seems like 0x20 (space character) is "OR"ed with the 7 bit address inside the library to create the 10 bit address for the I2C registers after the first access (or maybe it is cleared by mistake to a " " rather than ""). I also noticed the same problem exists in the NECTO as the libararies are shared.
I have built lots of boards which cannot be used with Mikroe toolchain I have been using Mikroe compilers extensively in the past few years and would love to see this resolved .
sample of the code for the issue
Code: Select all
unsigned char TestData1=112;
unsigned char TestData2=113;
unsigned char Register1=0x0F; //Registery to read from Sensor 1
unsigned char Register2=0x00; //Registery to read from sensor 2
unsigned char Sensor1=0x5C; // Address of Sensor 1
unsigned char Sensor2=0x68; //Address of Sensor 2
void PrintHandler(char c){
UART2_Write(c);
}
void main() {
I2C1_Init();
Delay_ms(150);
UART2_Init(115200);
Delay_ms(150);
I2C_Set_Active(&I2C1_Start, &I2C1_Read, &I2C1_Write);
while (1){
Delay_ms(1000);
//// first sensor routine
I2C_Start();
I2C_Write(Sensor1,&Register1,1,END_MODE_RESTART);
I2C_Read(Sensor1,&TestData1,1,END_MODE_STOP);
PrintOut(PrintHandler,"Value of the sensor 1 is %d \n",TestData1);
TestData1=0;
//// Second sensor routine
I2C_Start();
I2C_Write(Sensor2,&Register2,1,END_MODE_RESTART);
I2C_Read(Sensor2,&TestData2,1,END_MODE_STOP);
PrintOut(PrintHandler,"Value of the Psensor 2 is %d \n",TestData2);
TestData2=0;
}
}