📄 spi.c
字号:
#include "spiw.h"
#include "interrupt_mapping.h"
#include "inth2.h"
#include "UART_IrDA.h"
#include "global_types.h"
void spi_reset()
{
SetGroupBits32(SPI_SCR_REG,SPI_SCR_SOFTRESET_POS,SPI_SCR_SOFTRESET_NUMB,1); //softreset
while(!(SPI_SSR_REG & 0x01));
UART_Printf(UART2,"SPI module softreset over\n");
SPI_SCR_REG = 0x00000010; //smart idle
}
void spi_tx_master()
{
SPI_SET1_REG = 0x0006; // PTV=3
SPI_SET1_REG |= 0x0001; // enable SPI functional clock
SPI_SET2_REG = 0x8000; // master mode, select device 0 interface mode;
SPI_CTRL_REG = 0x003c; // enable device 0
//16bits transmit
SPI_TX_REG = 0x5555;
SPI_CTRL_REG |= 0x02; //active write
}
void spi_trx_master()
{
unsigned long temp;
SPI_TEST_REG |= 0x1; // spi test mode;
SPI_SET1_REG = 0x0006; // PTV=3
SPI_SET1_REG |= 0x0001; // enable SPI functional clock
SPI_SET2_REG = 0x8000; // master mode, select device 0 interface mode;
SPI_CTRL_REG = 0x007c; // enable device 0
//16bits transmit
SPI_TX_REG = 0x12345678;
SPI_CTRL_REG |= 0x03; //active write
while(!(SPI_ISR_REG & 0x1));
temp = SPI_RX_REG;
if(temp == 0x12345678)
UART_Printf(UART2,"SPI T/R success\n");
else
UART_Printf(UART2,"SPI T/R test error\n");
}
void SPI_test_menu()
{
int val = 1;
spi_reset();
while(val)
{
UART_Printf(UART2,"\r\n");
UART_Printf(UART2,"==========================================\r\n");
UART_Printf(UART2," ARM BENCH ----- MCSI Test Menu\r\n");
UART_Printf(UART2,"==========================================\r\n");
UART_Printf(UART2,"0 : Back to upper menu \r\n");
UART_Printf(UART2,"1 : SPI Tx_Master without DMA \r\n");
UART_Printf(UART2,"2 : SPI TRx_Master without DMA \r\n");
UART_Printf(UART2,"3 : SPI Tx with DMA \r\n");
UART_Printf(UART2,"5 : SPI Rx with DMA \r\n");
UART_Printf(UART2,"------------------------------------------ \r\n");
UART_Printf(UART2,"Please Enter your choice: \r\n ");
val = UART_GetNum(UART2);
UART_Printf(UART2,"\n\r");
switch (val)
{
case 0:
break;
case 1:
{
spi_tx_master();
break;
}
case 2:
{
spi_trx_master();
break;
}
case 3:
{
// MCSI_Tx_with_DMA(1);
break;
}
case 4:
{
//(2);
break;
}
case 5:
{
// MCSI_Tx_without_DMA(2);
break;
}
default:
UART_Printf(UART2,"You have select the wrong choice\n\r");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -