S3C6410 SPI全双工读写流程分析
一、SPI控制器datasheet
1详细请参考:http://blog.csdn.net/hustyangju/article/details/20474659
2 SPI的所有寄存器都是映射到内核空间的,采用基地址+偏移地址的方式访问
static volatile void __iomem *spiregs; //global variable for mapping spiregister
spiregs = (volatile)ioremap(0x7F00B000,0x30); //just request for the spi0
3 下文可能用到的偏移地址
#define S3C_CH_CFG (0x00) //SPI configuration
#define S3C_CLK_CFG (0x04) //Clock configuration
#define S3C_MODE_CFG (0x08) //SPI FIFO control
#define S3C_SLAVE_SEL (0x0C) //Slave selection
#define S3C_SPI_INT_EN (0x10) //SPI interrupt enable
#define S3C_SPI_STATUS (0x14) //SPI status
#define S3C_SPI_TX_DATA (0x18) //SPI TX data
#define S3C_SPI_RX_DATA (0x1C) //SPI RX data
#define S3C_PACKET_CNT (0x20) //count how many data master gets
#define S3C_PENDING_CLR (0x24) //Pending clear
#define S3C_SWAP_CFG (0x28) //SWAPconfig register
#define S3C_FB_CLK (0x28) //SWAP FB config register
#define SPI_CH_SW_RST (1<<5)
#define SPI_CH_MASTER (0<<4)
#define SPI_CH_SLAVE (1<<4)
#define SPI_CH_RISING (0<<3)
#define SPI_CH_FALLING (1<<3)
#define SPI_CH_FORMAT_A (0<<2)
#define SPI_CH_FORMAT_B (1<<2)
#define SPI_CH_RXCH_OFF (0<<1)
#define SPI_CH_RXCH_ON (1<<1)
#define SPI_CH_TXCH_OFF (0<<0)
#define SPI_CH_TXCH_ON (1<<0)
#define SPI_CLKSEL_PCLK (0<<9)
#define SPI_CLKSEL_USBCLK (1<<9)
#define SPI_CLKSEL_ECLK (2<<9)
#define SPI_ENCLK_DISABLE (0<<8)
#define SPI_ENCLK_ENABLE (1<<8)
#define SPI_MODE_CH_TSZ_BYTE (0<<29)
#define SPI_MODE_CH_TSZ_HALFWORD (1<<29)
#define SPI_MODE_CH_TSZ_WORD (2<<29)
#define SPI_MODE_BUS_TSZ_BYTE (0<<17)
#define SPI_MODE_BUS_TSZ_HALFWORD (1<<17)
#define SPI_MODE_BUS_TSZ_WORD (2<<17)
#define SPI_MODE_RXDMA_OFF (0<<2)
#define SPI_MODE_RXDMA_ON (1<<2)
#define SPI_MODE_TXDMA_OFF (0<<1)
#define SPI_MODE_TXDMA_ON (1<<1)
#define SPI_MODE_SINGLE (0<<0)
#define SPI_MODE_4BURST (1<<0)
#define SPI_SLAVE_MAN (0<<1)
#define SPI_SLAVE_AUTO (1<<1)
#define SPI_SLAVE_SIG_ACT (0<<0)
#define SPI_SLAVE_SIG_INACT (1<<0)
#define SPI_INT_TRAILING_DIS (0<<6)
#define SPI_INT_TRAILING_EN (1<<6)
#define SPI_INT_RX_OVERRUN_DIS (0<<5)
#define SPI_INT_RX_OVERRUN_EN (1<<5)
#define SPI_INT_RX_UNDERRUN_DIS (0<<4)
#define SPI_INT_RX_UNDERRUN_EN (1<<4)
#define SPI_INT_TX_OVERRUN_DIS (0<<3)
#define SPI_INT_TX_OVERRUN_EN (1<<3)
#define SPI_INT_TX_UNDERRUN_DIS (0<<2)
#define SPI_INT_TX_UNDERRUN_EN (1<<2)
#define SPI_INT_RX_FIFORDY_DIS (0<<1)
#define SPI_INT_RX_FIFORDY_EN (1<<1)
#define SPI_INT_TX_FIFORDY_DIS (0<<0)
#define SPI_INT_TX_FIFORDY_EN (1<<0)
#define SPI_STUS_TX_DONE (1<<21)
#define SPI_STUS_TRAILCNT_ZERO (1<<20)
#define SPI_STUS_RX_OVERRUN_ERR (1<<5)
#define SPI_STUS_RX_UNDERRUN_ERR (1<<4)
#define SPI_STUS_TX_OVERRUN_ERR (1<<3)
#define SPI_STUS_TX_UNDERRUN_ERR (1<<2)
#define SPI_STUS_RX_FIFORDY (1<<1)
#define SPI_STUS_TX_FIFORDY (1<<0)
#define SPI_PACKET_CNT_DIS (0<<16)
#define SPI_PACKET_CNT_EN (1<<16)
二、重点参数及初始化步骤
1 双通道SPI管脚配置
2 传输模型配置
/* Set transfer type (CPOL & CPHA set) */
spi_chcfg= SPI_CH_RISING | SPI_CH_FORMAT_A;
spi_chcfg|= SPI_CH_MASTER;
writel(spi_chcfg , spiregs + S3C_CH_CFG);
详细请参考:http://blog.csdn.net/hustyangju/article/details/20474659
3 时钟配置
使用PCLK,外部时钟66M,100分屏:
/* Set clock configuration register
* SPIclockout = clock source / (2 * (prescaler +1))
* PCLK=66Mhz, SPI clockout = clock source /(2 * (prescaler +1)) */
spi_clkcfg= SPI_ENCLK_ENABLE;
spi_clkcfg|= SPI_CLKSEL_PCLK;
writel(spi_clkcfg , spiregs + S3C_CLK_CFG);
spi_clkcfg= readl( spiregs + S3C_CLK_CFG);
spi_clkcfg|= 49; // the least spi speed =660Khz
writel(spi_clkcfg , spiregs + S3C_CLK_CFG);
4 SPI 模块设置
/* Set SPI MODE configuration register */
spi_modecfg= SPI_MODE_CH_TSZ_BYTE| SPI_MODE_BUS_TSZ_BYTE;
spi_modecfg|= SPI_MODE_TXDMA_OFF| SPI_MODE_SINGLE| SPI_MODE_RXDMA_OFF;
spi_modecfg&= ~( 0x3f << 5);
spi_modecfg|= ( 0x1 << 5); // Tx FIFOtrigger level in INT mode
spi_modecfg&= ~( 0x3f << 11);
spi_modecfg|= ( 0x1 << 11); // Rx FIFOtrigger level in INT mode
spi_modecfg&= ~( 0x3ff << 19);
spi_modecfg|= ( 0x1 << 19); // Counting ofTailing Bytes
writel(spi_modecfg,spiregs + S3C_MODE_CFG);
设置在fifo和bus中的数据宽度为byte,关闭DMA访问fifo,并设置fifo中保存最大字节数为1,设置接收和发送fifo的触发值为1byte。
5 中断配置
/* SetSPI INT_EN register */
writel(spi_inten,spiregs + S3C_SPI_INT_EN); //u32 spi_inten =0x00
writel(0x1f,spiregs + S3C_PENDING_CLR);
6 设置最大接收数据包数量
SPI can control the number of packets to bereceived in master mode. If there is any number of packets to bereceived, justset the SFR (Packet_Count_reg). SPI stops generating SPICLK when the number ofpackets is thesame as what you set. It is mandatory to follow software orhardware reset before this function is reloaded.(Software reset can clear allregisters except special function registers, but hardware reset clears allregisters.)
上一篇:ARM程序剖析--ARM程序结构,Image文件结构等
下一篇:qt-embedded-linux-opensource-src-4.5.3移植到s3c6410
推荐阅读最新更新时间:2024-11-16 10:14
设计资源 培训 开发板 精华推荐
- ATSAM9713GS Waveblaster 兼容使用具有 512 Kb x16 ROM(8 Mbits)的 ATSAM9713
- LTM8073IY 从同一输入源供电以获得更多输出电流的典型应用电路
- 单相PFC电源基础仿真电路
- ALT-ALSPIR-GEVK:环境光传感器 (ALS) 和接近屏蔽板
- LOWVOLTAGEP2SGEVB:三个 LED 低压并联串联照明电路
- 棒式应变仪
- 使用 NXP Semiconductors 的 ISP1161 的参考设计
- TLV431系列限流稳压器的典型应用
- LTC4446 的典型应用 - 高压高侧/低侧 N 沟道 MOSFET 驱动器
- 使用三个 iCoupler 的半双工单通道系统隔离
- Allegro MicroSystems 在 2024 年德国慕尼黑电子展上推出先进的磁性和电感式位置感测解决方案
- 左手车钥匙,右手活体检测雷达,UWB上车势在必行!
- 狂飙十年,国产CIS挤上牌桌
- 神盾短刀电池+雷神EM-i超级电混,吉利新能源甩出了两张“王炸”
- 浅谈功能安全之故障(fault),错误(error),失效(failure)
- 智能汽车2.0周期,这几大核心产业链迎来重大机会!
- 美日研发新型电池,宁德时代面临挑战?中国新能源电池产业如何应对?
- Rambus推出业界首款HBM 4控制器IP:背后有哪些技术细节?
- 村田推出高精度汽车用6轴惯性传感器
- 福特获得预充电报警专利 有助于节约成本和应对紧急情况