cancel
Showing results for 
Search instead for 
Did you mean: 

Function use in stm32 Library

ALE1
Associate II

as you can see below , i am writing a function from stm32 library

void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data)

the question is, can i use it in main file like

I2C_SendData(I2C1,(uint8_t*)data_t);

can i go from "uint8_t Data"" to ""(uint8_t*)data_t"

may i use pointer ?

Thanks

3 REPLIES 3
TDK
Guru

You can't give it a pointer if it's expecting a value instead. You'll need to send values one at a time.

If you switch to the HAL library, you can send multiple bytes at once with HAL_I2C_Master_Transmit.

If you feel a post has answered your question, please click "Accept as Solution".
ALE1
Associate II

Thanks for your reply!

actually i have to transmit data to LCD 16X2, i know it works for HAL_I2C_Master_Transmit.

what do you mean sending values one at a time ? i write code below, can you kindly check

void lcd_send_cmd (char cmd)

{

 char data_u, data_l;

uint8_t data_t[4];

data_u = (cmd&0xf0);

data_l = ((cmd<<4)&0xf0);

data_t[0] = data_u|0x0C; //en=1, rs=0

data_t[1] = data_u|0x08; //en=0, rs=0

data_t[2] = data_l|0x0C; //en=1, rs=0

data_t[3] = data_l|0x08; //en=0, rs=0

//HAL_I2C_Master_Transmit (i2c1, SLAVE_ADDRESS_LCD,(uint8_t *) data_t);

 I2C_GenerateSTART(I2C1, ENABLE);             

 while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));   

  

I2C_Send7bitAddress(I2C1, SLAVE_ADDRESS_LCD, I2C_Direction_Transmitter);  

 while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

  

I2C_SendData(I2C1,(uint8_t*)data_t);                     

 while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); 

TDK
Guru

> I2C_SendData(I2C1,(uint8_t*)data_t);

That won't even compile. Did you try to compile?

I think you need to understand the fundamental difference between (uint8_t) and (uint8_t *). This is a basic C programming concept.

If you feel a post has answered your question, please click "Accept as Solution".