LoginSignup
1
1

More than 1 year has passed since last update.

STM32F767でSPIを使いEEPROM AT93C46を読み出す。

Last updated at Posted at 2021-06-01

目的
SPIのテスト

前提
事前にアドレス0に1,2が書き込まれている

参考


#include "mbed.h"

SPI spi( D11 , D12 , D13); // mosi, miso, sclk
DigitalOut cs( D10 );

//Serial pc(USBTX, USBRX); // tx, rx
Serial pc(SERIAL_TX, SERIAL_RX); //767

int main() {
    pc.printf("\r\n767\r\n");

    // Setup the spi for 8 bit data, high steady state clock,
    // second edge capture, with a 1MHz clock rate
    spi.format(8,0);
    spi.frequency(1000000);

    // Select the device by seting chip select low
    cs = 1;

    spi.write(0b00000001);  
    spi.write(0b10000000 | 0);         
    wait_ms(5);    

    uint8_t b1 =  spi.write(0x00);
    uint8_t b2 =  spi.write(0x00);
    uint8_t b3 =  spi.write(0x00); 

    pc.printf("番地(H) = ");
    pc.printf("%d\r\n",
        (b1 << 1) | (b2 >> 7)
    );


    pc.printf("番地(L) = ");      
    pc.printf("%d\r\n",
    ( (b2 & 0b01111111) << 1)  | (b3 >> 7)
    );

    // Deselect the device
    cs = 0;
}



spi_eeprom_767_r_1.jpg

spi_eeprom_767_r_2.jpg

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1