Justin Richards
2018-08-11 11:09:39 UTC
Probably best posed in an arduino forum but hoping someone could pick an
obvious mistake, steer me in the right direction or suggest a better way.
I have generally avoided the << and >> operators but I thought they would
be ideal to pack a 32bit variable with commands.
So trying this
uint32_t ds = ('D'<<24)|('C'<<16) |('B'<<8)|('A');
when compiled for an ESP8266 target in arduino IDE and printed gives
0x44434241 as expected.
when the target is UNO it produces
0x4241
Doing this
uint32_t ds = 'D';
ds = (ds << 8)| 'C';
ds = (ds << 8)| 'B';
ds = (ds << 8)| 'A';
for either target works ok.
I have tried type casting (not sure that is the right phrase) like
uint32_t ds = uint32_t('D'<<24)|uint32_t('C'<<16)
|uint32_t('B'<<8)|uint32_t('A');
But no joy for the uno target.
The final goal is to construct SPI commands with a esp8266 master with a
UNO slave.
The following compiles and works fine for the esp8266 target but has the
issues mentioned above for the UNO target.
#define UNO1_ADDR uint32_t(uint32_t('U')|uint32_t('1'<<8)) //Address UNO1
#define cmdREADPIN uint32_t(UNO1_ADDR | uint32_t('R'<<16))
#define cmdWRITEPIN uint32_t((UNO1_ADDR | uint32_t('W'<<16))
#define cmdREADPIN1 uint32_t(cmdREADPIN | uint32_t('1'<<24))
#define cmdREADPIN2 uint32_t(cmdREADPIN | uint32_t('2'<<24))
#define cmdREADPIN3 uint32_t(cmdREADPIN | uint32_t('3'<<24))
Any tips?
Justin
obvious mistake, steer me in the right direction or suggest a better way.
I have generally avoided the << and >> operators but I thought they would
be ideal to pack a 32bit variable with commands.
So trying this
uint32_t ds = ('D'<<24)|('C'<<16) |('B'<<8)|('A');
when compiled for an ESP8266 target in arduino IDE and printed gives
0x44434241 as expected.
when the target is UNO it produces
0x4241
Doing this
uint32_t ds = 'D';
ds = (ds << 8)| 'C';
ds = (ds << 8)| 'B';
ds = (ds << 8)| 'A';
for either target works ok.
I have tried type casting (not sure that is the right phrase) like
uint32_t ds = uint32_t('D'<<24)|uint32_t('C'<<16)
|uint32_t('B'<<8)|uint32_t('A');
But no joy for the uno target.
The final goal is to construct SPI commands with a esp8266 master with a
UNO slave.
The following compiles and works fine for the esp8266 target but has the
issues mentioned above for the UNO target.
#define UNO1_ADDR uint32_t(uint32_t('U')|uint32_t('1'<<8)) //Address UNO1
#define cmdREADPIN uint32_t(UNO1_ADDR | uint32_t('R'<<16))
#define cmdWRITEPIN uint32_t((UNO1_ADDR | uint32_t('W'<<16))
#define cmdREADPIN1 uint32_t(cmdREADPIN | uint32_t('1'<<24))
#define cmdREADPIN2 uint32_t(cmdREADPIN | uint32_t('2'<<24))
#define cmdREADPIN3 uint32_t(cmdREADPIN | uint32_t('3'<<24))
Any tips?
Justin
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist