How to send array of hex to SPI MOSI?

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Nake350
Posts: 8
http://meble-kuchenne.info.pl
Joined: Tue May 11, 2021 10:53 pm
Has thanked: 3 times
Been thanked: 1 time

How to send array of hex to SPI MOSI?

Post by Nake350 »

I need to send configuartion info to a SiLabs wireless transiever by SPI, but not sure how to send such an array of numbers in a sequential stream.
I am using the SPI macro in other parts of the project for simple variables with good results.

The C code created by the Wireless transiever configuration app looked like below, so I want to integrate into my flowcode project

#define RF_WRITE_TX_FIFO 0x66, 0x8D, 0x2A, 0x70, 0x45, 0x32, 0x0D, 0x8E, 0x2B, 0x2A, 0x0E, 0xFC, 0x37, 0x77, 0x35, 0x5B, 0xC6, 0x3F, 0x1C, 0xED, \
0xC5, 0xC8, 0xEA, 0xA2, 0xDF, 0xCA, 0xF6, 0xA7, 0x4F, 0x8E, 0xA3, 0xC2, 0x63, 0x39, 0xD4, 0x9A, 0x04, 0xE8, 0x45, 0xB4, \
0xA1, 0xA7, 0x68, 0x85, 0x4D, 0x8D, 0x56, 0x34, 0xE2, 0x36, 0xF6, 0x25, 0x66, 0xE9, 0xEE, 0x6C, 0x0C, 0xBF, 0x5D, 0xE4, \
0xD0, 0x4C, 0x00, 0x9E, 0x45, 0xEA, 0x9C, 0xE7, 0x45, 0xC7, 0x0F, 0xBD, 0x05, 0x1A, 0x40, 0xB3, 0xC4, 0x3E, 0xE6, 0xF6, \
0xC4, 0xAD, 0x7B, 0xDB, 0x69, 0x2E, 0xCA, 0x78, 0x09, 0xCA, 0xAC, 0xD8, 0xE3, 0x88, 0xD1, 0x10, 0x20, 0x18, 0x3B, 0x8F, \
0x7B, 0x18, 0x6C, 0x1B, 0xA8, 0x56, 0xF9, 0xB7, 0x03, 0xCC, 0x28, 0x9C, 0xB1, 0xFB

Is there a way to do such a thing?

Thanks

mnfisher
Valued Contributor
Posts: 1213
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 118 times
Been thanked: 622 times

Re: How to send array of hex to SPI MOSI?

Post by mnfisher »

If you are using v9 - create an array :

byte x[sz] (where sz is the number of values) and in the initial value set:

{ paste your values -> 0xNN, 0xNN, 0xNN ... } Values enclosed in braces '{' and '}'

Then you can just write them out using a loop

In pseudocode:
for .i = 0..sz - 1
spi.out (x[.i])

which will do exactly what you need..

In v8 - you can use a lookup table in a similar manner...

Martin

Nake350
Posts: 8
Joined: Tue May 11, 2021 10:53 pm
Has thanked: 3 times
Been thanked: 1 time

Re: How to send array of hex to SPI MOSI?

Post by Nake350 »

Many thanks for your help Martin,

Yes, I'm using FC9, but without sounding too dumb, what feature do you mean to create an array and enter values in please?

I am trying with 'SendByteArray' macro, with data BYTE being a variable with values added as you stated (which is now being accepted without syntax errors since adding the '{' and '}'

With trial values entered in the variable, it's looping round but no values being sent accoring to the Oscilloscope?

EDIT: I found I set the variable as a string, so when tried as a Byte, but with an array of values it works with the SPI as needed. :D

Thanks again,

Nick

mnfisher
Valued Contributor
Posts: 1213
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 118 times
Been thanked: 622 times

Re: How to send array of hex to SPI MOSI?

Post by mnfisher »

Glad to hear you've got it working...

Yes - I've been caught using a string as an array of bytes issue too - sometimes you can get away with this, and sometimes it throws up some unusual errors..

Martin

Post Reply