我从网上下载了一个cc2540 SPI 的代码,学习了一下,想用示波器看一下MOSI 的输出是什么样的。
我可以明显看到SSN的变化,但是看不到SCK(P1_5) 和 MOSI (P1_6) 有任何信号。
然后我用debug 模式 用了一个watch 去看U1DBUF,然后他一直是0x00, 相当于没有写进去。
搞了好几天了,不知道问题出在哪了,求大家给点指导意见。 真的万分感谢。
#include <ioCC2540.h>
#include "hal_cc8051.h"
#define LED1 P1_0
#define LED2 P1_1
#define LED_OFF 0
#define LED_ON 1
void main()
{
//unsigned char temp = 0;
CLKCONCMD = 0x80; while (CLKCONSTA != 0x80); // 32MHz
// SPI Master Mode
PERCFG |= 0x02; // map USART1 to its alternative 2 location. P1_4: SSN, P1_5: SCK, P1_6: MOSI, P1_7: MISO
P1SEL |= 0xE0; // P1_5, P1_6, and P1_7 are peripherals
P1SEL &= ~0x10; // P1_4 is GPIO (SSN)
P1DIR |= 0x10; // SSN is set as output
U1BAUD = 0x00; U1GCR |= 0x11; // Set baud rate to max (system clock frequency / 8)
U1CSR &= ~0xA0; // SPI Master Mode
// U1CSR &= ~0x80; U1CSR |= 0x20; // SPI Slave Mode
U1GCR &= ~0xC0; U1GCR |= 0x20; // MSB
IO_FUNC_PORT_PIN(1, 0, IO_FUNC_GIO); // 将P1_0设置为普通IO口
IO_DIR_PORT_PIN(1, 0, IO_OUT); //设置为输出
LED1 = 0;
while(1)
{
P1_4 = 0; // SSN LOW
U1DBUF = 0x55;
while (!(U1CSR&0x02)); // wait for TX_BYTE to be set
U1CSR &= ~0x02;
U1DBUF = 0x0a;
while (!(U1CSR&0x02));
U1CSR &= ~0x02;
//temp = U1DBUF;
P1_4 = 1; // SSN high
LED1=~LED1;
halMcuWaitMs(300);
}
}