How to convert byte array to single point value in matlab function for compiling for TI C2000 hardware
Afficher commentaires plus anciens
I have a matlab function block I'm trying to compile for the C2000 hardware (F28069M chip in particular). The block brings in a 8-byte message from a canbus port read, which I'm trying to use the Typecast function to convert the 8 bytes into two "single" values. If I use something like:
byte1=DataIn(5);
byte2=DataIn(6);
byte3=DataIn(7);
byte4=DataIn(8);
X=uint8([byte1 byte2 byte3 byte4]);
DataOut = typecast(X,'single');
I get the error "For code generation, interger input or result classes for typecast must map directly to a C type in the target hardware"
if I try to specify the C2000 data type 'float' or 'float32', I get an error on compiling "Unsupported data type for conversion"
Is there a way to do this type of typecast (from 4-byte array to float) as part of a matlab function for the C2000 hardware?
Réponses (1)
Mark McBroom
le 16 Mar 2024
0 votes
byte1 = bitshift(uint32(DataIn(5)),24);
byte2 = bitshift(uint32(DataIn(6)),16);
byte3 = bitshift(uint32(DataIn(7)),8);
byte4 = uint32(DataIn(8));
DataOut = single(byte1+byte2+byte3+byte4);
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!