⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi_str75x.c

📁 keil arm flash fs 最新版 在Keil arm下使用
💻 C
字号:
/*----------------------------------------------------------------------------
 *      R T L  -  F l a s h   F i l e   S y s t e m
 *----------------------------------------------------------------------------
 *      Name:    SPI_STR75X.C 
 *      Purpose: Serial Peripheral Interface Driver for STR75x
 *      Rev.:    V3.22
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include <File_Config.h>
#include <75x_lib.h>                    /* STR750 definitions                */

/* SSP_SR - bit definitions. */
#define TFE     0x01
#define TNF     0x02
#define RNE     0x04
#define RFF     0x08
#define BSY     0x10

/*----------------------------------------------------------------------------
 *      SPI Driver Functions
 *----------------------------------------------------------------------------
 *  Required functions for SPI driver module:
 *   - void spi_init ()
 *   - void spi_ss (U32 ss)
 *   - U8   spi_send (U8 outb)
 *   - void spi_hi_speed (BOOL on)
 *---------------------------------------------------------------------------*/

/*--------------------------- spi_init --------------------------------------*/

void spi_init (void) {
   /* Initialize and enable the SSP Interface module. */

   /* SCLK0, MISO0, MOSI0 are SSP pins. */
   GPIO0->PC0 |=  0x000000F0;
   GPIO0->PC1 &= ~0x00000010;
   GPIO0->PC1 |=  0x000000E0;
   GPIO0->PC2 |=  0x000000F0;
   /* NSS is GPIO, output set to high. */
   GPIO0->PD  |= 0x00000010;

   /* Enable SPI in Master Mode, CPOL=0, CPHA=0. */
   SSP0->CR0 = 0x0007;
   SSP0->CR1 = 0x0002;
   SSP0->PR  = 0xFE;
}


/*--------------------------- spi_hi_speed ----------------------------------*/

void spi_hi_speed (BOOL on) {
   /* Set a SPI clock to low/high speed for SD/MMC. */

   if (on == __TRUE) {
      /* Max. 20 MBit used for Data Transfer. */
      SSP0->PR = 0x02;
   }
   else {
      /* Max. 400 kBit used in Card Initialization. */
      SSP0->PR = 0xFE;
   }
}


/*--------------------------- spi_ss ----------------------------------------*/

void spi_ss (U32 ss) {
   /* Enable/Disable SPI Chip Select (drive it high or low). */

   if (ss) {
      /* NSS is GPIO, output set to high. */
      GPIO0->PD |=  0x00000010;
   } 
   else {
      /* NSS is GPIO, output set to low. */
      GPIO0->PD &= ~0x00000010;
   }
}


/*--------------------------- spi_send --------------------------------------*/

U8 spi_send (U8 outb) {
   /* Write and Read a byte on SPI interface. */

   /* Wait if TNF cleared, Tx FIFO is full. */
   while (!(SSP0->SR & TNF));
   SSP0->DR = outb;

   /* Wait if RNE cleared, Rx FIFO is empty. */
   while (!(SSP0->SR & RNE));
   return (SSP0->DR);
}


/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -