Skip to main content
csp_kc
Associate II
November 12, 2018
Solved

How to use I2C_Write Block in Matlab Simulink with Input Data port enabled?

  • November 12, 2018
  • 1 reply
  • 2907 views

I am trying to send a uint8 through the "Input Data" port on the I2C_Write block. According to the I2C polling example the block expects a uint8. However, when I build the C code and look at it in Keil I get an error in the "User's Data declarations for I2C_Write" saying

"Error: Cannot take the address of an rvalue of type 'uint8_T' (aka 'unsigned char')

I have provided screen shots of my project

This topic has been closed for replies.
Best answer by Taylor Hillegeist

Looks like things are a bit broken. My guess would be that the address isn't being handled properly. Looking at the tlc file for the block which should be in the install directory I see the following.

STM32\blks\mex\tlc_c\I2C_Write.tlc on line 230

 %else
 %if !%<LibIsEmpty(Target_Register)>				
 %assign Data_str = LibBlockInputSignal(0, "", "", 0)
 uint8_t* %<block_name>_aTxBuffer = &%<Data_str>;				
 %endif
 %endif

I think this is not suppose to be done this way:

https://www.mathworks.com/help/releases/R2018b/rtw/tlc/input-signal-functions.html?searchHighlight=libblockinputsignal&s_tid=doc_srchtitle

0690X000006CMRMQA4.png

I would look into the function LibBlockInputSignaladdr instead.

1 reply

Taylor Hillegeist
Associate
November 12, 2018

Looks like things are a bit broken. My guess would be that the address isn't being handled properly. Looking at the tlc file for the block which should be in the install directory I see the following.

STM32\blks\mex\tlc_c\I2C_Write.tlc on line 230

 %else
 %if !%<LibIsEmpty(Target_Register)>				
 %assign Data_str = LibBlockInputSignal(0, "", "", 0)
 uint8_t* %<block_name>_aTxBuffer = &%<Data_str>;				
 %endif
 %endif

I think this is not suppose to be done this way:

https://www.mathworks.com/help/releases/R2018b/rtw/tlc/input-signal-functions.html?searchHighlight=libblockinputsignal&s_tid=doc_srchtitle

0690X000006CMRMQA4.png

I would look into the function LibBlockInputSignaladdr instead.

csp_kc
csp_kcAuthor
Associate II
November 14, 2018

Wow, thanks Taylor! Changing removing the LibBLockInputSignal and adding the LibBlockInputSignaladdr function in STM32\blks\mex\tlc_c\I2C_Write.tlc worked!

You should get a job at ST!