2013-10-19
CooCox OLimex SPI testing waveforms
int main()
{
testSpi01();
}
void testSpi01()
{
loopBackSpi02();
}
void loopBackSpi02()
{
// Setup and initialize buffers ***
#define BUFFER_SIZE 0x04
uint8_t Tx_Buf[BUFFER_SIZE];
uint8_t Rx_Buf[BUFFER_SIZE];
initBuffer(Tx_Buf, Rx_Buf, 0xa5, 0x00);
// Setup SPI0 with clock pin P06
setUpSpi050(SCK0_PIO0_6);
// Setup xfer data configuration struct
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = Tx_Buf;
xferConfig.rx_data = Rx_Buf;
xferConfig.length = BUFFER_SIZE;
// Start transfer
uint8_t j;
for (j = 0; j < 10000000; j++)
{
delayMilliSecond(1);
setGpioDataPinHigh01(PortPinArrayP03);
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinLow01(PortPinArrayP03);
}
...
}
.END
// ***********************************************************************
// Program - Fong EKG v5.0
// Function - Olimex EKG Board Evaluation
// Author - TL Fong
// Build - 2013.10.19.02
// Date - 2013oct19hkt1257
// Hardware - Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301/FN28
// 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()
{
// *** Completed tests ***
// testOlimexLedKey01();
// testWhutLedKey01();
// testWhut7segmentLed01();
// testOlimex7segmentLed01();
// *** Current test SPI ***
testSpi01();
return 0;
}
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// test050.h 2013oct19hkt1257
// ***********************************************************************
#include "led050.h"
#include "key050.h"
#include "spi050.h"
void testSpi01() // 2013oct19
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led
// *** Test SPI loopback ***
// loopBackSpi01();
loopBackSpi02();
}
void testOlimexLedKey01() // tested OK 2013oct13
{
// *** For all mcu boards - setup GPIO pin as out and toggle ***
setupGpioPinOutputLow050(PortPinArrayP09); // setup GPIO pin as ooutput
blinkLed0501(PortPinArrayP09); // blink led
// *** Olimex test only - setup I/O pins for testing ***
setupOlimexGpio050(); // setup Olimex GPIO pins as output and input
// *** Olimex test only - blink single LED and run all LEDs***
blinkOlimexLed(LED_7, ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_6_TIMES); // blink one Led
runOlimexLeds(); // sequentially blink all 8 Leds
// *** Olimex test only - echo key by led ***
echoOlimexKeyByLed(KEY_1, LED_1); // echo Olimex key by led
echoOlimexKeyByLed(KEY_2, LED_2); // echo Olimex key by led
echoOlimexKeyByLed(KEY_1, LED_3); // echo Olimex key by led
// *** For all mcu boards, given mcu board struct, echo key by led ***
echoKeyByLed0504(OlimexLpc1114DevBoardStruct, KEY_1, LED_5); // given mcuboard struct, echo key by led
}
void testWhutLedKey01() // tested OK 2013oct14
{
// *** For all mcu boards - setup GPIO pin as out and toggle ***
setupGpioPinOutputLow050(PortPinArrayP108); // setup LED1 pin
blinkLed0501(PortPinArrayP108); // blink LED1
// *** Whut only - setup I/O pins for testing ***
setupWhutGpio050(); // setup Olimex GPIO pins as output and input
// *** Whut only - blink single LED and run all LEDs***
blinkWhutLed(LED_1, ON_ONE_FIFTH_SECOND, OFF_ONE_FIFTH_SECOND, REPEAT_6_TIMES); // blink one Led
runWhutLeds(); // sequentially blink all 8 Leds
// *** Whut only - echo key by led ***
echoWhutKeyByLed(KEY_1, LED_1); // echo key by led
echoWhutKeyByLed(KEY_2, LED_2); // echo key by led
echoWhutKeyByLed(KEY_1, LED_3); // echo key by led
// *** For all mcu boards, given mcu board struct, echo key by led ***
echoKeyByLed0505(WhutLpc11c14DevBoardStruct, KEY_1, LED_2); // given mcuboard struct, echo key by led
}
void testWhut7segmentLed01()
{
// *** system self diagnostic test - blink LED P108 ***
setupGpioPinOutputLow050(PortPinArrayP108); // setup LED1 pin
blinkLed0501(PortPinArrayP108); // blink LED1
// *** Testing 7 segment LED ***
displayAllDigits050(WhutBoardSevenSegmentLedPortPinArrayPointerArray, MAX_WHUT_7_SEG_LED_PIN_NUMBER);
}
void testOlimex7segmentLed01()
{
// *** system self diagnostic test - blink LED P09 ***
setupGpioPinOutputLow050(PortPinArrayP09); // setup GPIO pin as output
blinkLed0501(PortPinArrayP09); // blink led
// *** Testing 7 segment LED ***
displayAllDigits050(OlimexBoardSevenSegmentLedPortPinArrayPointerArray, MAX_OLIMEX_7_SEG_LED_PIN_NUMBER);
}
// ***********************************************************************
// End
// ***********************************************************************
// ***********************************************************************
// spi050.h 2013oct19hkt1613
// ***********************************************************************
#include "lpc11xx_ssp.h"
#include "led050.h"
void loopBackSpi02()
{
// Setup and initialize buffers ***
#define BUFFER_SIZE 0x04
uint8_t Tx_Buf[BUFFER_SIZE];
uint8_t Rx_Buf[BUFFER_SIZE];
initBuffer(Tx_Buf, Rx_Buf, 0xa5, 0x00);
// Setup SPI0 with clock pin P06
setUpSpi050(SCK0_PIO0_6);
// Setup xfer data configuration struct
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = Tx_Buf;
xferConfig.rx_data = Rx_Buf;
xferConfig.length = BUFFER_SIZE;
// Start transfer
uint8_t j;
for (j = 0; j < 10000000; j++)
{
delayMilliSecond(1);
setGpioDataPinHigh01(PortPinArrayP03);
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinLow01(PortPinArrayP03);
}
// Check transferred data
/*
uint8_t xferStatus;
xferStatus = xferCheck(xferConfig.tx_data, xferConfig.rx_data);
if (xferStatus == 1)
blinkOneLed050(PortPinArrayP03, ONE_FIFTH_SECOND, ONE_HALF_SECOND, BLINK_6_TIMES);
else
blinkOneLed050(PortPinArrayP03, ONE_FIFTH_SECOND, ONE_HALF_SECOND, BLINK_8_TIMES);
*/
}
// *** Private SPI test functions ***
void setUpSpi050(SCK0_Position_Typedef sck0)
{
// Enable SSP0 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);
// Reset SSP0 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, DISABLE);
SYSCON_SetSPI0ClockDiv(10);
// Assign GPIO pins for SPI
SSP_SSP0PinsInit(sck0, ENABLE);
// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);
// Enable SSP peripheral
SSP_Cmd(LPC_SSP0, ENABLE);
}
void initBuffer(uint8_t Tx_Buf[BUFFER_SIZE], uint8_t Rx_Buf[BUFFER_SIZE], uint8_t TxInitByte, uint8_t RxInitByte)
{
uint8_t i;
for (i = 0; i < BUFFER_SIZE; i++)
{
Tx_Buf[i] = TxInitByte;
Rx_Buf[i] = RxInitByte;
}
}
/*
uint8_t xferCheck(uint8_t *Tx_Buf[], uint8_t *Rx_Buf[], uint8_t bufferSize)
{
uint8_t *src_addr = (uint8_t *) &Tx_Buf[0];
uint8_t *dest_addr = (uint8_t *) &Rx_Buf[0];
uint8_t i;
for ( i = 0; i < bufferSize; i++ )
{
if ( *src_addr++ != *dest_addr++ )
{
return 0;
}
}
return 1;
}
*/
void loopBackSpi01()
{
// Setup and initialize buffers ***
#define BUFFER_SIZE 0x04
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;
}
// Enable SSP0 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);
// Reset SSP0
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, DISABLE);
SYSCON_SetSPI0ClockDiv(10);
// Assign GPIO pins for SPI
SSP_SSP0PinsInit(SCK0_PIO0_6, ENABLE);
// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);
// Enable SSP peripheral
SSP_Cmd(LPC_SSP0, ENABLE);
// Test loop back
// Setup xfer data configuration struct
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = Tx_Buf;
xferConfig.rx_data = Rx_Buf;
xferConfig.length = BUFFER_SIZE;
// Testing transfer
uint8_t j;
for (j = 0; j < 10000000; j++)
{
delayMilliSecond(1);
setGpioDataPinHigh01(PortPinArrayP03);
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinLow01(PortPinArrayP03);
}
/*
// Check if SPI transfer OK
int xferStatus;
xferStatus = xferCheck(Tx_Buf, Rx_Buf);
if (xferStatus == 1)
blinkOneLed050(PortPinArrayP03, ONE_FIFTH_SECOND, ONE_HALF_SECOND, BLINK_6_TIMES);
else
blinkOneLed050(PortPinArrayP03, ONE_FIFTH_SECOND, ONE_HALF_SECOND, BLINK_8_TIMES);
*/
}
// ***********************************************************************
// End
// ***********************************************************************
.END
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment