Go Down

Topic: SPI using 24-bit addressing mode... Please help... (Read 692 times) previous topic - next topic

RicThot

Hi guys,

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:

Code: [Select]

  int address=0;

  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?

Thanks!

Krupski

#1
Feb 01, 2013, 04:26 am Last Edit: Feb 01, 2013, 04:31 am by Krupski Reason: 1

Hi guys,

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:

Code: [Select]

   int address=0;

 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?

Thanks!


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.
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

RicThot

The shifting explanation makes lots of sens, thanks for this!

The data I'm getting from the chip doesn't make sense though - not sure if it's the addressing, but something is wrong with the reading.
I'm not getting what I was expecting at all...

I'll try to post an example a bit later.

Go Up