Skip to content

Instantly share code, notes, and snippets.

@surinoel
Last active July 29, 2019 13:19
Show Gist options
  • Save surinoel/0f6d5f907574b129b811e74956c139ed to your computer and use it in GitHub Desktop.
Save surinoel/0f6d5f907574b129b811e74956c139ed to your computer and use it in GitHub Desktop.
uint8_t *arr;
void w25q_fast_read(uint32_t addr, uint32_t size)
{
arr = (uint8_t *)malloc(sizeof(uint8_t)*size);
uint8_t cmd[3];
uint8_t trashval;
cmd[0] = (addr >> 16) & 0xFF;
cmd[1] = (addr >> 8) & 0xFF;
cmd[2] = addr & 0xFF;
w25q_ss_pin_drive(LOGIC_LOW);
spi_transmit(0x0B);
spi_transmit(cmd[0]);
spi_transmit(cmd[1]);
spi_transmit(cmd[2]);
trashval = spi_transmit(0x00);
for(int i=0; i<size; i++) {
arr[i] = spi_transmit(0x00);
}
w25q_ss_pin_drive(LOGIC_HIGH);
while(getstatus());
}
/*
* w25q64_readwrite.c
*
* Created: 2019-07-28 오후 4:47:14
* Author : yeong
*/
#define F_CPU 16000000UL
#include <util/delay.h>
#include <avr/io.h>
#include "uart.h"
#include "spi.h"
#include "w25q64.h"
uint8_t wData[0x100];
extern uint8_t *arr;
int main(void)
{
spi_init();
uart0_init();
// CS init
w25q_ss_pin_init();
for(int i=0; i<0x100; i++) {
wData[i] = i;
}
erase_block(0);
_delay_ms(500);
w25q_page_write(0, wData, 0x100);
_delay_ms(5);
w25q_fast_read(0x00, 0x100);
for(int i=0; i<0x100; i++) {
printf("%02X:%d\r\n", i, arr[i]);
_delay_ms(100);
}
while (1)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment