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


目的
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;
}