Pages: [1]   Go Down
Author Topic: SPI using 24-bit addressing mode... Please help...  (Read 558 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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!
Logged

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 799
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
   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.
« Last Edit: January 31, 2013, 10:31:42 pm by Krupski » Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: