Advertisement
sniper_nuko

SPI_Comm

Nov 4th, 2020
1,826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. // SPI通信開始
  2. static void spi_flash_comm_start(void)
  3. {
  4.     // SPIO SSEL2 "L"
  5.     *pPORTFIO_CLEAR = PF8;
  6.     ssync();
  7.    
  8.     NOP();
  9.     NOP();
  10.     NOP();
  11.     NOP();
  12. }
  13.  
  14. // SPI通信終了
  15. static void spi_flash_comm_end(void)
  16. {
  17.     int32_t tim;
  18.    
  19.     // SPIO SSEL2 "H"
  20.     *pPORTFIO_SET = PF8;
  21.     ssync();
  22.    
  23.     for(tim = 0; tim < (100 / 2.5); tim++) NOP();
  24. }
  25.  
  26. // 1バイト転送
  27. static uint8_t spi_flash_transfer(uint8_t trn_data)
  28. {
  29.     // データ転送
  30.     *pSPI0_TDBR = trn_data;
  31.     ssync();
  32.    
  33.     // 転送完了まで待機
  34.     while((*pSPI0_STAT & RXS) == 0) ssync();
  35.  
  36.     // 受信データを取得
  37.     return *pSPI0_RDBR;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement