Trying to use the SPIEEPROM tutorial to read a Winbond W25Q16BV chip, which uses 24-bit addressing.
The tutorial is based on a chip using 16-bits addressing. When reading data from the chip, it passes the read address using 2 separate bytes:
spi_transfer((char)(address>>8)); //send MSByte address first
spi_transfer((char)(address)); //send LSByte address
I've been reading and trying to understand the shifting for a couple hours now but I can't figure this out. Since the chip I want to read from uses 24-bit addressing, I guess I'll have to use 3 bytes to passe the address - but how would I code this?
What you need to do 24 bits is a 32 bit variable like this:00000000 11111111 10101010 00110110
The first (char) is (variable) which is 00110110
Next (char) is (variable >> 8) or 10101010
Next (char) is (variable >> 16) or 11111111
You have now shifted out 24 bits. Make sense?(edit to add):
You need a long int or a uint32_t. A plain int is only 16 bits.