cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 HAL I2C

Juniorkgtech
Associate

Good morning, I'm having trouble understanding how to solve a problem.
there is already a software developed in keil 4, but we need to change some things but now we will use keil 5 with the hal library, so far ok without problems.

my first problem was with the i2c which is ready but uses 4 eeprom 24aa1025 on my board. attached is the diagram of the board (already working but with keil 4 software without hal library).

the problem is that the programmer retired and I had to take on the job of converting the software because of a touchpanel on the “stone” which is using the HAL library,

the old code uses the command “I2C_SendData(I2C1,AddressMEM>>8);” and the new i2c library doesn't have it and I'm a bit confused about the system that has been set up.

The AddressMEM variable is working perfectly as far as the address of the bytes to be read is concerned, the problem is passing this command to the

HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout),

where it has 7 parameters, or the command to read the bytes as well.

Attached are the keil 4 i2c.c and i2c.h files.

 

Could someone help me?

7 REPLIES 7

@Juniorkgtech wrote:

The AddressMEM variable is working perfectly as far as the address of the bytes to be read is concerned


Not quite sure what you mean by that?

 

@Juniorkgtech wrote:

the problem is passing this command to the

HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout),

where it has 7 parameters, or the command to read the bytes as well.


What, exactly, is the problem here?

See the documentation of the HAL_I2C_Mem_Write function - it's in the source code, and there will also be a PDF version for the particular STM32 family you're using.

I would suggest that you start by using one of the example projects, to get familiar with how the HAL I2C works ...

 

 

 

and on my board I have 4 eeprom of 1024k.

and in the old software this part of the code is defined in i2c.h

#define EEPROM_MANUFACTURER_PW 131283 //(4 Bytes) Password of manufacturer

how do i read this address from the hal library?

I've been racking my brain for 2 days if you could enlighten me I'd be grateful.

 

 

It looks like your original code is based on the old Standard Peripheral Library (SPL) - yes?

Do you have a particular reason to change from that?

 


@Juniorkgtech wrote:

in the old software this part of the code is defined in i2c.h

#define EEPROM_MANUFACTURER_PW 131283 //(4 Bytes) Password of manufacturer

how do i read this address from the hal library?


What do you mean by that?

It's just a C #define - you use it just as you did previously.

 

Again, if you do want/need to move to HAL, then start by using  the example projects, to get familiar with how the HAL I2C works ...

 

You still haven't said what STM32 you're using, but here's the F0 version - with documentation:

/**
  * @brief  Write an amount of data in blocking mode to a specific memory address
  * @PAram  hi2c Pointer to a I2C_HandleTypeDef structure that contains
  *                the configuration information for the specified I2C.
  * @PAram  DevAddress Target device address: The device 7 bits address value
  *         in datasheet must be shifted to the left before calling the interface
  * @PAram  MemAddress Internal memory address
  * @PAram  MemAddSize Size of internal memory address
  * @PAram  pData Pointer to data buffer
  * @PAram  Size Amount of data to be sent
  * @PAram  Timeout Timeout duration
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_I2C_Mem_Write( I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress,
                                    uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout )

 

With the HAL memory functions you can create an array of bytes for the transaction, and can specify if the address within the EPROM is 1 or 2 bytes wide. It will then do the >>8 operation for the high order byte.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

 

yes, I was using the SPL library. the reason is that we are using a “Stone hmi” touchpanel which uses the HAL library, that is the reason.

 

 

the family i am using project is F1.

 

Fair enough.

So, again, start with the HAL examples to get an understanding of how the HAL works, and how to use it.

 


@Juniorkgtech wrote:

the family i am using project is F1.


So here's the documentation, etc:

https://www.st.com/en/embedded-software/stm32cubef1.html

 

PS:

 


@Juniorkgtech wrote:

we are using a “Stone hmi” touchpanel which uses the HAL library


So this: https://www.aliexpress.com/item/1005003680251065.html ?

But that says it has RS232 interface ?

 

PPS:

Or this: https://www.stoneitech.com/industrial-type/

"Intelligent TFT LCD module with UART port can be controlled by any MCU via simple JSON Code Instructions set & powerful GUI design software"

So it's just a UART interface - the display itself neither knows nor cares anything about HAL ...


@Andrew Neil wrote:

Fair enough.

So, again, start with the HAL examples to get an understanding of how the HAL works, and how to use it.

 


@Juniorkgtech wrote:

the family i am using project is F1.


So here's the documentation, etc:

https://www.st.com/en/embedded-software/stm32cubef1.html

 

PS:

 


@Juniorkgtech wrote:

we are using a “Stone hmi” touchpanel which uses the HAL library


So this: https://www.aliexpress.com/item/1005003680251065.html ?

But that says it has RS232 interface ?

 

PPS:

Or this: https://www.stoneitech.com/industrial-type/

"Intelligent TFT LCD module with UART port can be controlled by any MCU via simple JSON Code Instructions set & powerful GUI design software"

So it's just a UART interface - the display itself neither knows nor cares anything about HAL ...


yes json, but they created a new library that uses some HAL instructions, I even spent 2 days as stone support because I had some errors that weren't working.
Our old version was developed in a way that is outdated and no longer accesses the necessary information of the new STONE model, and in contact with stone support they passed me their library that in this new one I need to improve all my software.

 

i will try....

 

thank you