Accessing STM32 Registers with Necto

General discussion on mikroC AI for ARM.
Post Reply
Author
Message
Dr.AMS
Posts: 6
Joined: 22 Aug 2020 01:21

Accessing STM32 Registers with Necto

#1 Post by Dr.AMS » 23 Aug 2020 07:41

Hi I have made the switch and have purchased the Necto for ARM. I have one questions and also one problem.

Question:

How do you access STM32 registers in Necto for example

Code: Select all

I2C1_CR2bits.SADD=0;
this used to be possible with Mikroc Pro for ARM but in Necto i get the error undeclared identifier.

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;
}
}
Regards

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: Accessing STM32 Registers with Necto

#2 Post by filip.grujcic » 24 Aug 2020 15:46

Hello,

For the I2C1_CR2bits issue in NECTO -- in the Project Manager, right click on your project and select Manage Project Libraries, expand mikroC and make sure System library is checked.

For the I2C library bug, please replace your library file with the attached one in:
...\Mikroelektronika\mikroC PRO for ARM\Uses\ST M4

Let me know if this fixes the problem.

Best regards,
Attachments
__Lib_I2C_32Lxxx_13.zip
(9.47 KiB) Downloaded 81 times
Filip Grujcic

Dr.AMS
Posts: 6
Joined: 22 Aug 2020 01:21

Re: Accessing STM32 Registers with Necto

#3 Post by Dr.AMS » 25 Aug 2020 15:15

Hi filip

Thank you for your reply and the file that you sent. Unfortunately the substitution of the library file broke the I2C completely. Now it will only try to connect to 0x00 no matter which address you select. I had to revert back to the old library files.

Regards

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Accessing STM32 Registers with Necto

#4 Post by AntiMember » 25 Aug 2020 17:23

Dr.AMS wrote:
23 Aug 2020 07:41
Hi I have made the switch and have purchased the Necto for ARM. I have one questions and also one problem.

Question:

How do you access STM32 registers in Necto for example

Code: Select all

I2C1_CR2bits.SADD=0;
this used to be possible with Mikroc Pro for ARM but in Necto i get the error undeclared identifier.

Now the issue
Maybe in Necto add

Code: Select all

 typedef struct tagI2C1_CR2BITS {
  union {
    struct {
      unsigned SADD : 10;
      unsigned RD_WRN : 1;
      unsigned ADD10 : 1;
      unsigned HEAD10R : 1;
      unsigned START : 1;
      unsigned STOP_ : 1;
      unsigned NACK : 1;
      unsigned NBYTES : 8;
      unsigned RELOAD : 1;
      unsigned AUTOEND : 1;
      unsigned PECBYTE : 1;
      unsigned : 5;
    };
  };
} typeI2C1_CR2BITS;
sfr volatile typeI2C1_CR2BITS I2C1_CR2bits absolute 0x40005404;
If name conflict - change I2C1_CR2BITS.
It will be faster this way ...

Post Reply

Return to “mikroC AI for ARM General”