Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- Yanagihara
- Date:
- 2021-09-12
- Revision:
- 0:29e55001d8e4
- Child:
- 1:534cb807eeff
File content as of revision 0:29e55001d8e4:
#include "mbed.h"
SPI spi(p5,p6,p7); //mosi,miso,sclk
DigitalOut cs(p8);
Serial pc(USBTX,USBRX); //tx,rx
/*Flashのコマンドを発行*/
#define CMD_RDID 0x9f //
//#define CMD_READ 0x03 // Address Read Data
uint8_t d;
void spi_init(){ /*spi通信設定*/
spi.format(8,0);
spi.frequency(1000000); // 1,000,000=1MHz clock rate
cs = 1; //初期化
}
void flash_rdid(uint8_t* rx_buf, uint16_t length){ /*RDID読み出し*/
cs = 0;
spi.write(CMD_RDID);
for(int i=0 ; i<length ; i++){
d = spi.write(0x00);
if(rx_buf != NULL){
rx_buf[i] = d;
}
}
cs = 1;
}
void data_debug_printf(const uint8_t* data, uint16_t bytes){ //配列を表示
pc.printf("-----------------------------------------------\r\n");
for(int i=0; i<bytes; i++){
pc.printf("[%d]:%d\r\n",i,data[i]);
}
}
int main() {
uint8_t rx_buf[256]; // 受信バッファ用意
spi_init(); // spi初期設定
printf("RDID\r\n");
flash_rdid(rx_buf, 4); // RDID読み出し関数
data_debug_printf(rx_buf, 4); // 取得データ表示
}
// 読み出し用メモ//
// const uint32_t address = 0000000; // 0000000h(hは16進数の証)
// /* フラッシュから構造体にデータを読み込む */
// loadFlash(address, (uint8_t*)&chimame, sizeof(Chimame));
// test = readData;