www.pudn.com > arm_spi_note.zip > spi.c, change:2016-11-27,size:1440b


//mosi -> io口7  -> GPB_3
//miso -> io口8  -> GPB_2
//clk  -> io口9  -> GPB_0
//cs   -> io口10 -> GPB_1
//SCLk_mpll(800mhz)->(mux spi0-2)->div spi0(1-16)->spi0-2 pre(1-256)
//->sclk_spi(100mhz)->div(2)->spi_clk(max 50mhz)
//div spi0 = spi0_ratio和spi0_pre_ratio在 clk_div_peril1 寄存器里
//1142页
//GPIO_BASE 0x1140_0000 GPB +0040

#define mux_spi         *(unsigned int *)0x1003c254
#define spi_ratio       *(unsigned int *)0x1003c554
#define ch_cfg          *(unsigned int *)0x13920000 //spi通道模式
#define mode_cfg        *(unsigned int *)0x13920000 //spi模式
#define spi_pend        *(unsigned int *)0x13920024
#define spi_cs          *(unsigned int *)0x1392000c
#define spi_packet      *(unsigned int *)0x13920020 //packet_cnt寄存器
#define spi_status      *(unsigned int *)0x13920014 //状态寄存器
#define spi_fbclk       *(unsigned int *)0x1392002c //fb_clk寄存器
#define tx_data         *(unsigned int *)0x13920018
#define rx_data         *(unsigned int *)0x1392001c
#define gpb_con         *(unsigned int *)0x11400040

void (*printf)(char *, ...) = (void *)0x43e11434;

void _start(void)
{
  gpb_con |= 0x2222;
  mux_spi &= ~0xf;
  mux_spi = 6<<16; //配置选择mpll时钟源 800mhz
  spi_ratio |= 0x31<<8|7;   //配置分频为8,输出100mhz
  ch_cfg |=1<<6|1;        //使能spi 输入输出
  spi_cs =3;
  while (1)
  { 
  if(!(spi_status & 0x1)) 
  tx_data=0xae;
  printf("%p\n",spi_status);
  }
}