This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
我用的是1611 主频8M SPI设置时钟模式1 能正常读写
现在外设器件要求模式0或3
我改变设置模式的CKPL,CKPH 读写就不正常了
写55 模式3读出的是AA 模式0不管写什么读的都是6C
初始化程序如下,请大家帮忙看看,非常感谢!
void init_SPI(void)
{ UCTL1=SWRST;
UCTL1=CHAR+SYNC+MM; //设置 8-bit 字符模式,主模式
UTCTL1= SSEL1+SSEL0+STC; // 设置 SMCLK 和 3-pin 模式,默认时钟为低;
U1BR0 = 0x02; //设置波特率
U1BR1 = 0x00;
U1MCTL = 0x00;
UCTL1&=~SWRST;
ME2 |= USPIE1; // 使能 USART1 SPI 模式
P5SEL |= 0x0e; //P5.1~3 置位外围模块
P5DIR&=~BIT2;
P5DIR|=BIT1;
P5DIR|=BIT3;
}
// MSP430F21x2
// -----------------
// /|\| XIN|-
// | | |
// HC165 --|RST XOUT|-
// ---------- | |
// 8 | /LD|<---|P3.6 |
// -\->|A-H CLK|<---|P3.0/UCA0CLK |
// |-|INH QH|--->|P3.5/UCA0SOMI |
// |-|SER | | |
// v
//
//
// A. Dannenberg
// Texas Instruments Inc.
// October 2006
// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.41A
//******************************************************************************
#include "msp430x21x2.h"
volatile unsigned char Data;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P3SEL |= 0x21; // P3.0,5 USCI_A0 option select
P3DIR |= 0x40; // P3.6 output direction
UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x02;
UCA0BR1 = 0; //
UCA0MCTL = 0;
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
发一个标准的spi配置代码,可以参考一下
我试了一个铁电存储器也是一样的 只有模式1可以正常读写,别的模式都不行,USB芯片测试SPI程序也是一样的现象。模式1没问题,写入0X55,模式0读出的是没规律数据,模式1读的是55,模式2读的是AA,模式3读出的是D5。