首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

关于9s12的SPI

关于9s12的SPI

我做了需要开发一个采集系统.需要AD采集,采用SPI通讯.但我看资料时发现9s12dg128的SPI很怪异,它只有两个SPI寄存器组,但在管脚上确有四个借口,分别SPI0:S口和P口各一个,SPI1在H口和M口各一个,但我对寄存器进行设置,但在任何一个口都没有测到通讯波形.哪位大哥知道,请赐教
************************************************************ * SpiDemo - Demonstrates the use of the 68HC12 SPI by * interfacing with a 74HC595 and 74HC165. * * Controller: 68HC912B32 * Monitor: D-Bug12 * * 3/5/98 Todd Morton ************************************************************ * Equates ************************************************************ PORTS equ $d6 DDRS equ $d7 DDRP equ $57 PORTP equ $56 PP0 equ $01 SS equ %10000000 MOSI equ %00100000 SCK equ %01000000 SP0CR1 equ $d0 SP0CR2 equ $d1 SP0BR equ $d2 SP0SR equ $d3 SP0DR equ $d5 SPIF equ $80 INPUT equ $0fe0 OUTBYTE equ $0fe6 ************************************************************ * Program ************************************************************ * Initialize SPI * Set SPI outputs as outputs in DDRS * SS pin is the latch clock for 74HC595. * Set for 1Mbps * Set PORTP bit0 for 74HC165 latch clock * Clear SPIF ************************************************************ org $0800 main bset DDRS,SS|MOSI|SCK bset PORTS,SS bset DDRP,PP0 bset PORTP,PP0 movb #$5c,SP0CR1 movb #$02,SP0BR ldaa SP0SR ;clear flag ldaa SP0DR ************************************************************ * Main interface loop * A simple test loop that sends the ascii character * entered out to the 74HC595. It then reads a value * from the 74HC165 and displays it. * For testing connect the 74HC595 Qn's to the 74HC165 n's * This will cause the ascii character of the key pressed * be echoed. ************************************************************ next_in jsr INPUT beq next_in jsr SpiOut jsr SpiIn pshb tfr sp,d jsr OUTBYTE pulb bra next_in ************************************************************ * SpiOut - Output routine for a 74HC595. It uses SS as the * latch clock.(SS is a GP output) * Spi Initialization: (could be done in main init if it * was the only setup needed) * SPCR = $5c ->SPI Enable,Master,CPOL:CPHA = 11 * The data to be sent out is passed in ACCB. Result of * dummy read is returned in ACCB. * All other registers are preserved except CCR ************************************************************ SpiOut movb #$5c,SP0CR1 stab SP0DR ;Output data wait_spiout brclr SP0SR,SPIF,wait_spiout ;Wait for shift complete bclr PORTS,SS ;Transfer SR->Latch bset PORTS,SS ldab SP0DR ;dummy read to clear SPIF rts ************************************************************ * SpiIn - Input routine for a 74HC165. It uses PP0 as the * latch clock. * Spi Initialization: (could be done in main init if it * was the only setup needed) * SPCR = $58 ->SPI Enable,Master,CPOL:CPHA = 10 * The dummy data to be sent out is passed in ACCB. Input * value is returned in ACCB. * All other registers are preserved except CCR ************************************************************ SpiIn bclr PORTP,PP0 ;Transfer SR<-Latch bset PORTP,PP0 movb #$58,SP0CR1 stab SP0DR ;Dummy data wait_spiin brclr SP0SR,SPIF,wait_spiin ;Wait for shift complete ldab SP0DR rts
哥们,多多交流,我可不是FREESCALE 的技术支持
谢谢yanjihu,我看到了,9S12的spi输出各有两组管脚.由MODRR寄存器控制.(在资料S12DTB128PIMV2.pdf中有说明).
我用的是9S12和AD7705连接,SPI我调通了,不过不知道什么原因通讯不稳定,在多字节读写时命令就乱了.我实在是没有时间在这里磨蹭,昨天下午只能废掉SPI功能,用IO口模拟了,AD已经调试完了.
问题没有解决,欢迎各位大虾指点,我实在没有时间了,如果以后有时间,我肯定把SPI做完,把结果给各位,不过可要以后再说了
不过这么做可能增加了CPU功耗,这是个问题
返回列表