CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Read/Write w25q32
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19217

View user's profile Send private message

PostPosted: Mon Jun 01, 2020 12:47 am     Reply with quote

Or, look at how I've done it with the union.

I pass an 'int32' to the functions as an address, but tell the compiler
this is a union between an int32, and 4*int8's. A union, uses the same
'space' in memory for the declared parts, so the int8's are the four
bytes of the int32. You can read or write to these, and the int32 then
contains the whole 'assembly'....
temtronic



Joined: 01 Jul 2010
Posts: 9101
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jun 01, 2020 4:33 am     Reply with quote

I see you only have 3 bytes and need to use an int32....
When using either make32() or union , have a 4th 'dummy' byte as a 'filler' to keep the compiler happy. Wile I KNOW the compiler is much smarter than me, this litle bit of housekeeping might prevent some 'bug' for some version of compiler from doing odd things.....
Also when using make32(), be sure the order of the 4 bytes is correct ! I wondered for a few hours why my program was giving 'interesting' numbers only to FINALLY see the order of the bytes was reversed......
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Jun 01, 2020 9:18 am     Reply with quote

Definitely structs/unions are the way to go.

Although I never really leave out members of a struct.

For the sake of the compiler guessing or the next reader of my code, I tend to fully justify structs with an even int/byte worth of "stuff" (like 8bits for 8bit CPUs, 16bits for 16bit CPUs and so on)
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ttelmah



Joined: 11 Mar 2010
Posts: 19217

View user's profile Send private message

PostPosted: Mon Jun 01, 2020 9:56 am     Reply with quote

If you look at what I posted, I input an int32, and then just output the
three low bytes. Since the source value is an int32, all four bytes
'exist', just omitting one on the output is not a problem. Very Happy
However using it the other way, I'd either 'preload' with a zero value,
or include the fourth byte.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group