// ***********************************************************************
// Program - Fong EKG v5.0
// Function - Olimex EKG Board Evaluation
// Author - TL Fong
// Build - 2013.10.18.01
// Date - 2013oct18hkt1650
// Hardware - Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301
// Olimex EKG board (SHIELD-EKG/EMG Rev B, Bulgaria 2011)
// Software - GCC ARM 4.7, CoIDE 1.7.4, CoLinkEx 1.1, Flash Magic v7.51
// ***********************************************************************
#include "test050.h" // main tests
// ***********************************************************************
// Main Function
// ***********************************************************************
int main()
{
...
testSpi01();
return 0;
}
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// test050.h 2013oct18hkt1640
// ***********************************************************************
#include "led050.h"
#include "key050.h"
#include "spi050.h"
void testSpi01() // 2013oct18
{
// *** For all mcu boards - setup GPIO pin as out and toggle ***
setupGpioPinOutputLow050(PortPinArrayP09); // setup GPIO pin as output
blinkLed0501(PortPinArrayP09); // blink led
// *** Test SPI loopback ***
loopBackSpi01();
}
...
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// spi050.h 2013oct18hkt1626
// ***********************************************************************
#include "lpc11xx_ssp.h"
#include "led050.h"
void loopBackSpi01()
{
// *** setup transmit and receive buffers ***
// Max buffer length
#define BUFFER_SIZE 0x40
// Tx buffer
uint8_t Tx_Buf[BUFFER_SIZE];
// Rx buffer
uint8_t Rx_Buf[BUFFER_SIZE];
// *** configure SPI peripheral ***
// SSP Configuration structure variable
SSP_CFG_Type SSP_ConfigStruct;
// 1. Enable SSP0 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);
// 2. Assign P2.11 as SCK0, enable SSEL
// ********** SSP_SSP0PinsInit(SCK0_PIO2_11, ENABLE); // !!! system hangs !!!
// 3.1 Initialize SSP configuration structure to default
SSP_ConfigStructInit(&SSP_ConfigStruct);
// 3.2 Initialize SSP peripheral with parameter given in structure above
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);
// 4. Enable SSP peripheral
SSP_Cmd(LPC_SSP0, ENABLE);
// 5.1 Initialize buffers
xferBuffer_Init(Tx_Buf, Rx_Buf);
// 5.2 Setup transmit data configuration struct
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = Tx_Buf;
xferConfig.rx_data = Rx_Buf;
xferConfig.length = BUFFER_SIZE;
// 5.3 Read and write SPI data
// !!! System hangs !!! SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
// 5.4 Check if SPI transfer OK
int xferStatus;
xferStatus = xferStatusCheck(Tx_Buf, Rx_Buf);
if (xferStatus == 1)
blinkOneLed050(PortPinArrayP09, ONE_FIFTH_SECOND, ONE_HALF_SECOND,
BLINK_2_TIMES);
else
blinkOneLed050(PortPinArrayP09, ONE_FIFTH_SECOND, ONE_HALF_SECOND,
BLINK_4_TIMES);
}
// *** Private SPI test functions ***
void xferBuffer_Init(uint8_t Tx_Buf[BUFFER_SIZE], uint8_t Rx_Buf[BUFFER_SIZE] )
{
uint8_t i;
for (i = 0; i < BUFFER_SIZE; i++)
{
Tx_Buf[i] = i;
Rx_Buf[i] = 0;
}
}
int xferStatusCheck(uint8_t Tx_Buf[BUFFER_SIZE], uint8_t Rx_Buf[BUFFER_SIZE])
{
uint8_t i;
uint8_t *src_addr = (int *) &Tx_Buf[0];
uint8_t *dest_addr = (int *) &Rx_Buf[0];
for ( i = 0; i < BUFFER_SIZE; i++ )
{
if ( *src_addr++ != *dest_addr++ )
{
return 0;
}
}
return 1;
}
// ***********************************************************************
// End
// ***********************************************************************
No comments:
Post a Comment