|
主程序如下:
/*本程序将配置SSI0成SPI主模式 通过主模式的TX发三个字符并从主模式的RX接收*/
/*
SSI0 外设
GPIO Port A SSI0使用管脚
SSI0CLK - PA2
SSI0Fss - PA3
SSI0Rx - PA4
SSI0Tx - PA5
串口UART0外设
GPIO Port A UART0使用管脚
UART0RX - PA0
UART0TX - PA1
*/
#include "inc/hw_memmap.h"
#include "inc/hw_ssi.h"
#include "inc/hw_types.h"
#include "driverlib/ssi.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "utils/uartstdio.h"
#include "driverlib/pin_map.h"
/*定义发送的字节数*/
#define NUM_SSI_DATA 3
/*串口0显示通讯信息*/
#define GPIO_PA0_U0RX 0x00000001
#define GPIO_PA1_U0TX 0x00000401
#define GPIO_PA2_SSI0CLK 0x00000801
#define GPIO_PA3_SSI0FSS 0x00000C01
#define GPIO_PA4_SSI0RX 0x00001001
#define GPIO_PA5_SSI0TX 0x00001401
void
InitConsole(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // 使能 UART0用到的GPIO port A
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0); //初始化UART控制所需I/O
}
/*将SSI0配置成SPI主模式*/
int main(void)
{
unsigned long ulDataTx[NUM_SSI_DATA];
unsigned long ulDataRx[NUM_SSI_DATA];
unsigned long ulindex;
// 设置时钟从外部晶振运行
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
// 设置串行控制用于信息的显示
InitConsole();
UARTprintf("SSI ->\n");
UARTprintf(" Mode: SPI\n");
UARTprintf(" Data: 8-bit\n\n");
// 使能SSI0
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
//使能SSI0所用到的端口A的管脚
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//给A2, A3, A4, A5配置SSI0引脚复用功能
GPIOPinConfigure(GPIO_PA2_SSI0CLK);
GPIOPinConfigure(GPIO_PA3_SSI0FSS);
GPIOPinConfigure(GPIO_PA4_SSI0RX);
GPIOPinConfigure(GPIO_PA5_SSI0TX);
// 配置为SSI的GPIO引脚
GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
GPIO_PIN_2);
// 配置并启用SSI端口为SPI主模式
SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER, 1000000, 8);
// 使能SSI0模块
SSIEnable(SSI0_BASE);
// 读来自SSI端口的数据
while(SSIDataGetNonBlocking(SSI0_BASE, &ulDataRx[0]))
{
}
// 初始化要发送数据
ulDataTx[0] = 's';
ulDataTx[1] = 'p';
ulDataTx[2] = 'i';
UARTprintf("Sent:\n ");
// 发送3字节数据
for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++)
{
// 显示SSI发送的数据
UARTprintf("'%c' ", ulDataTx[ulindex]);
/* Send the data using the "blocking" put function. This function
will wait until there is room in the send FIFO before returning.
This allows you to assure that all the data you send makes it into
the send FIFO*/
SSIDataPut(SSI0_BASE, ulDataTx[ulindex]);
}
//
// 等待SSI0把所有数据都传进发送FIFO
while(SSIBusy(SSI0_BASE))
{
}
// Display indication that the SSI is receiving data.
UARTprintf("\nReceived:\n ");
// 接收3字节的数据
for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++)
{
SSIDataGet(SSI0_BASE, &ulDataRx[ulindex]);
// 使用8位数据,屏蔽掉 MSB.
ulDataRx[ulindex] &= 0x00FF;
UARTprintf("'%c' ", ulDataRx[ulindex]); //显示接收到的数据
}
return(0);
}
编译后出现的错误如下,请高手指点下,我是初学M4,谢谢
spi.axf: Error: L6366E: uart.obj attributes are not compatible with the provided cpu and fpu attributes .
spi.axf: Error: L6366E: sysctl.obj attributes are not compatible with the provided cpu and fpu attributes .
spi.axf: Error: L6366E: interrupt.obj attributes are not compatible with the provided cpu and fpu attributes .
spi.axf: Error: L6366E: gpio.obj attributes are not compatible with the provided cpu and fpu attributes .
spi.axf: Error: L6366E: cpu.obj attributes are not compatible with the provided cpu and fpu attributes .
|
|