This is the pinout I have for the flash memory W25Q128FV which I'm trying to interact with
I'm trying to control it with a raspberry pi 3 B+.
Here's how I wired everything:
CS - GND
D0 - SPIMISO
WP - GND
GND - GND
VCC - 3.3v
HOLD - 3.3v
CLK - SPISCLK
DI - SPIMOSI
CS is in GND because datasheet says that in LOW, we can write/read from the chip, but I think this is wrong. I need to connect this to some raspberry pi pin that maybe is controlled by wiring pi.
I also enabled spi on raspberry and I'm using the library wiringPi with channel 0.
I'm writing like this (Rust code linked against -lwiringPi):
pub fn read_status_register_3(&self) -> [u8;2]{
let mut slice :[u8;2] = [0;2];
let mut data: [::std::os::raw::c_char; 2] = [0;2];
data[0] = 0x11;
let mut _r: i32 = 0;
_r = unsafe{wiringPiSPIDataRW (self.spi_channel,data.as_mut_ptr(), data.len() as i32)};
slice.clone_from_slice(&data);
slice
}
but I get data
to be all 0
. I suspect something is wrong but I don't know if it's on the chip, on the wiring or on the software. This is a brand new chip by the way.
datasheet link: http://www.xmcwh.com/Uploads/2020-09-03/5f50d26953af2.pdf
Here's my Rust code with everything ready to test and dockerized, just ./run.sh
, compile the Wiringpi/wiringpi with ./build
and cargo run
in w25qxx_spi
: https://github.com/lucaszanella/w25qxx_spi/blob/b652db39d83521d7f018bd254c1b3dca03549f00/w25qxx_spi/src/w25q.rs
wiringPi
has been deprecated. It still works - at least I still use it occasionally, but if you've not used it much, you should be aaware that is uses a unique numbering scheme for GPIO pins. You can print those from wiringPi, or use this tool, and hover over the pin to see the "tool tip".