cancel
Showing results for 
Search instead for 
Did you mean: 

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

csp_kc
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
Taylor Hillegeist
Associate II

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.

View solution in original post

2 REPLIES 2
Taylor Hillegeist
Associate II

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.

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!