2013-12-01
SPI testing notes
// ***************************************************************************
// Program - Fong EKG v0.94
// Function - Testing Olimex EKG
// Author - TL Fong
// Build - 2013.12.01.01
// Date - 2013dec01hkt1715
// Hardware - WuyinS/Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301
// Olimex EKG/EMG R.B 2011
// Software - CoIDE 1.7.5, CoLinkEx 1.1, Flash Magic v7.66, GCC ARM 4.7
// **************************************************************************
#include "test050.h"
// ***************************************************************************
// Main Function
// ***************************************************************************
int main()
{
// testMax7219DisplayEightDigitV093();
// testMax7219DisplayEightDigitV094();
// testMax7219DisplayEightDigitV095();
testMax7219DisplayEightDigitV096(); itermittantly fails
}
// ***************************************************************************
// End
// ***************************************************************************
// ***********************************************************************
// test050.h 2013nov29hkt0952
// ***********************************************************************
#include "led050.h"
#include "key050.h"
#include "adc050.h"
#include "eeprom050.h"
#include "spi080.h"
#include "mled080.h"
#define DEBUG 1
#define NO_DEBUG 0
void testMax7219DisplayEightDigitV096()
{
// *** Set up SPI channels SPI0, SPI1 ***
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);
// *** Set up all slave select ports of SPI0, SPI1 ***
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);
// *** loop display 8 digits of each 8 MAX7219s, connected to SPI x,y ***
while (1)
{
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 7, 15, 0, 0, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 7, 15, 0, 1, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_2, 5, 14, 1, 15, 7, 15, 0, 2, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_3, 5, 14, 1, 15, 7, 15, 0, 3, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 8, 15, 1, 0, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_0, 5, 14, 1, 15, 7, 15, 1, 0, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_4, 5, 14, 1, 15, 7, 15, 1, 4, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_5, 5, 14, 1, 15, 7, 15, 1, 5, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_6, 5, 14, 1, 15, 7, 15, 1, 6, NO_DEBUG);
/*
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_1, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 7, 15, 0, 1, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_2, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 7, 15, 0, 2, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_3, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 7, 15, 0, 3, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 8, 15, 1, 0, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_4, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 8, 15, 1, 4, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_5, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 8, 15, 1, 5, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_6, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 8, 15, 1, 6, NO_DEBUG);
*/
}
}
void testMax7219DisplayEightDigitV095()
{
// *** Set up SPI channels SPI0, SPI1 ***
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);
// v094
// *** Set up all slave select ports of SPI0, SPI1 ***
// printf("\n*** Set up Slave select ports ***\n\n");
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);
// *** loop display 8 digits of each 8 MAX7219s, connected to SPI x,y ***
while (1)
{
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 7, 15, 0, 0, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_1, 5, 14, 1, 15, 7, 15, 0, 1, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_2, 5, 14, 1, 15, 7, 15, 0, 2, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_3, 5, 14, 1, 15, 7, 15, 0, 3, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_4, 5, 14, 1, 15, 7, 15, 0, 4, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_5, 5, 14, 1, 15, 7, 15, 0, 5, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_6, 5, 14, 1, 15, 7, 15, 0, 6, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_7, 5, 14, 1, 15, 7, 15, 0, 7, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_8, 5, 14, 1, 15, 7, 15, 0, 8, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_0, 5, 14, 1, 15, 7, 15, 1, 0, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_1, 5, 14, 1, 15, 7, 15, 1, 1, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_2, 5, 14, 1, 15, 7, 15, 1, 2, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_3, 5, 14, 1, 15, 7, 15, 1, 3, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_4, 5, 14, 1, 15, 7, 15, 1, 4, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_5, 5, 14, 1, 15, 7, 15, 1, 5, NO_DEBUG);
Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_6, 5, 14, 1, 15, 7, 15, 1, 6, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_7, 5, 14, 1, 15, 7, 15, 1, 7, NO_DEBUG);
//Max7219DisplayEightDigitV0905(SPI_CHANNEL_1, SLAVE_SELECT_8, 5, 14, 1, 15, 7, 15, 1, 8, NO_DEBUG);
}
}
void testMax7219DisplayEightDigitV094()
{
// *** Set up SPI channels SPI0, SPI1 ***
// printf("\n*** Set up SPI channels ***\n\n");
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);
// *** Set up all slave select ports of SPI0, SPI1 ***
// printf("\n*** Set up Slave select ports ***\n\n");
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_0]);
setupAllSlaveSelectPortV090(WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[SPI_CHANNEL_1]);
// *** loop display 8 digits of each 8 MAX7219s, connected to SPI x,y ***
while (1)
{
Max7219DisplayEightDigitV0905(SPI_CHANNEL_0, SLAVE_SELECT_0, 5, 14, 1, 15, 15, 15, 5, 5, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_1, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 0, 1, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_2, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 0, 2, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_3, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 0, 3, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_4, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 0, 4, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_5, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 0, 4, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_6, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 0, 6, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_7, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 0, 7, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_0, SLAVE_SELECT_8, WuyinsSpi0SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 0, 7, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_0, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 0, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_1, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 1, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_2, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 2, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_3, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 3, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_4, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 4, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_5, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 5, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_6, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 6, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_7, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 7, NO_DEBUG);
Max7219DisplayEightDigitV0903(SPI_CHANNEL_1, SLAVE_SELECT_8, WuyinsSpi1SselPortPinArrayPointerArrayV092, \
5, 14, 1, 15, 15, 15, 1, 8, NO_DEBUG);
}
}
// ***********************************************************************
// spi080.h 2013nov28hkt1000
// ***********************************************************************
#include "gpio050.h"
#include "led050.h"
#include "lpc11xx_ssp.h"
#include "semihosting.h"
#include "stdio.h"
#include "config050.h"
#ifndef SPI_HEADER_SEEN
#define SPI_HEADER_SEEN
// *** SPI #defines ***
#define MAX_SPI_CHANNEL_NUMBER 2
#define MAX_SPI_SLAVE_SELECT_NUMBER 9
#define SPI_CHANNEL_TOTAL 2
#define SPI_SLAVE_SELECT_TOTAL 9
#define SPI_CHANNEL_0 0
#define SPI_CHANNEL_1 1
#define SLAVE_SELECT_0 0
#define SLAVE_SELECT_1 1
#define SLAVE_SELECT_2 2
#define SLAVE_SELECT_3 3
#define SLAVE_SELECT_4 4
#define SLAVE_SELECT_5 5
#define SLAVE_SELECT_6 6
#define SLAVE_SELECT_7 8
#define SLAVE_SELECT_8 8
typedef int slaveSelectPortPinArray[2];
typedef slaveSelectPortPinArray *slaveSelectPortPinArrayPointerArray[SPI_SLAVE_SELECT_TOTAL];
typedef slaveSelectPortPinArrayPointerArray *slaveSelectPortPinArrayPointerArrayPointerArray[SPI_CHANNEL_TOTAL];
slaveSelectPortPinArray SlaveSelectPortPinArray00 = {PORT0, PIN2};
slaveSelectPortPinArray SlaveSelectPortPinArray01 = {PORT3, PIN0};
slaveSelectPortPinArray SlaveSelectPortPinArray02 = {PORT3, PIN1};
slaveSelectPortPinArray SlaveSelectPortPinArray03 = {PORT3, PIN2};
slaveSelectPortPinArray SlaveSelectPortPinArray04 = {PORT3, PIN3};
slaveSelectPortPinArray SlaveSelectPortPinArray05 = {PORT2, PIN6};
slaveSelectPortPinArray SlaveSelectPortPinArray06 = {PORT2, PIN7};
slaveSelectPortPinArray SlaveSelectPortPinArray07 = {PORT2, PIN8};
slaveSelectPortPinArray SlaveSelectPortPinArray08 = {PORT2, PIN9};
slaveSelectPortPinArray SlaveSelectPortPinArray10 = {PORT2, PIN0};
slaveSelectPortPinArray SlaveSelectPortPinArray11 = {PORT3, PIN0};
slaveSelectPortPinArray SlaveSelectPortPinArray12 = {PORT3, PIN1};
slaveSelectPortPinArray SlaveSelectPortPinArray13 = {PORT3, PIN2};
slaveSelectPortPinArray SlaveSelectPortPinArray14 = {PORT3, PIN3};
slaveSelectPortPinArray SlaveSelectPortPinArray15 = {PORT2, PIN6};
slaveSelectPortPinArray SlaveSelectPortPinArray16 = {PORT2, PIN7};
slaveSelectPortPinArray SlaveSelectPortPinArray17 = {PORT2, PIN8};
slaveSelectPortPinArray SlaveSelectPortPinArray18 = {PORT2, PIN9};
slaveSelectPortPinArrayPointerArray WuyinsSlaveSelectPortPinArrayPointerArraySp0V095[SPI_SLAVE_SELECT_TOTAL] = \
{&SlaveSelectPortPinArray00, &SlaveSelectPortPinArray01, &SlaveSelectPortPinArray02, \
&SlaveSelectPortPinArray03, &SlaveSelectPortPinArray04, &SlaveSelectPortPinArray05, \
&SlaveSelectPortPinArray06, &SlaveSelectPortPinArray07, &SlaveSelectPortPinArray08};
slaveSelectPortPinArrayPointerArray WuyinsSlaveSelectPortPinArrayPointerArraySp1V095[SPI_SLAVE_SELECT_TOTAL] = \
{&SlaveSelectPortPinArray10, &SlaveSelectPortPinArray11, &SlaveSelectPortPinArray12, \
&SlaveSelectPortPinArray13, &SlaveSelectPortPinArray14, &SlaveSelectPortPinArray15, \
&SlaveSelectPortPinArray16, &SlaveSelectPortPinArray17, &SlaveSelectPortPinArray18};
slaveSelectPortPinArrayPointerArrayPointerArray \
WuyinsSlaveSelectPortPinArrayPointerArrayPointerArrayV095[SPI_CHANNEL_TOTAL] = \
{&WuyinsSlaveSelectPortPinArrayPointerArraySp0V095, \
&WuyinsSlaveSelectPortPinArrayPointerArraySp1V095};
// *** SPI PortPinArray assignment ***
portPinArray PortPinArraySsel0 = {PORT0, PIN2};
portPinArray PortPinArraySsel1 = {PORT2, PIN0};
portPinArray PortPinArraySsel00 = {PORT0, PIN2};
portPinArray PortPinArraySsel01 = {PORT3, PIN0};
portPinArray PortPinArraySsel02 = {PORT3, PIN1};
portPinArray PortPinArraySsel03 = {PORT3, PIN2};
portPinArray PortPinArraySsel04 = {PORT3, PIN3};
portPinArray PortPinArraySsel05 = {PORT2, PIN6};
portPinArray PortPinArraySsel06 = {PORT2, PIN7};
portPinArray PortPinArraySsel07 = {PORT2, PIN8};
portPinArray PortPinArraySsel08 = {PORT2, PIN9};
portPinArray PortPinArraySsel10 = {PORT2, PIN0};
portPinArray PortPinArraySsel11 = {PORT3, PIN0};
portPinArray PortPinArraySsel12 = {PORT3, PIN1};
portPinArray PortPinArraySsel13 = {PORT3, PIN2};
portPinArray PortPinArraySsel14 = {PORT3, PIN3};
portPinArray PortPinArraySsel15 = {PORT2, PIN6};
portPinArray PortPinArraySsel16 = {PORT2, PIN7};
portPinArray PortPinArraySsel17 = {PORT2, PIN8};
portPinArray PortPinArraySsel18 = {PORT2, PIN9};
portPinArray *Olimex2SlaveSelectPortPinArrayPointerArray0[] = {&PortPinArraySsel00, \
&PortPinArraySsel01, &PortPinArraySsel02, &PortPinArraySsel03, \
&PortPinArraySsel04, &PortPinArraySsel05, &PortPinArraySsel06};
portPinArray *Olimex2SlaveSelectPortPinArrayPointerArray1[] = {&PortPinArraySsel10, \
&PortPinArraySsel11, &PortPinArraySsel12, &PortPinArraySsel13, \
&PortPinArraySsel14, &PortPinArraySsel15, &PortPinArraySsel16};
portPinArray *Olimex20SlaveSelectPortPinArrayPointerArrayArray[2][7] = \
{&PortPinArraySsel00, &PortPinArraySsel01, &PortPinArraySsel02, \
&PortPinArraySsel03, &PortPinArraySsel04, &PortPinArraySsel05, \
&PortPinArraySsel06, \
&PortPinArraySsel10, &PortPinArraySsel11, &PortPinArraySsel12, \
&PortPinArraySsel13, &PortPinArraySsel14, &PortPinArraySsel15, \
&PortPinArraySsel16};
portPinArray *Olimex21SlaveSelectPortPinArrayPointerArrayArray[2][7] = \
{Olimex2SlaveSelectPortPinArrayPointerArray0, \
Olimex2SlaveSelectPortPinArrayPointerArray1};
portPinArray *WuyinsSpi0SselPortPinArrayPointerArray[] = {&PortPinArraySsel00, \
&PortPinArraySsel01, &PortPinArraySsel02, &PortPinArraySsel03, \
&PortPinArraySsel04, &PortPinArraySsel05, &PortPinArraySsel06};
portPinArray *WuyinsSpi1SselPortPinArrayPointerArray[] = {&PortPinArraySsel10, \
&PortPinArraySsel11, &PortPinArraySsel12, &PortPinArraySsel13, \
&PortPinArraySsel14, &PortPinArraySsel15, &PortPinArraySsel16};
portPinArray *WuyinsSpi0SselPortPinArrayPointerArrayV092[] = {&PortPinArraySsel00, \
&PortPinArraySsel01, &PortPinArraySsel02, &PortPinArraySsel03, \
&PortPinArraySsel04, &PortPinArraySsel05, &PortPinArraySsel06, \
&PortPinArraySsel07, &PortPinArraySsel08};
portPinArray *WuyinsSpi1SselPortPinArrayPointerArrayV092[] = {&PortPinArraySsel10, \
&PortPinArraySsel11, &PortPinArraySsel12, &PortPinArraySsel13, \
&PortPinArraySsel14, &PortPinArraySsel15, &PortPinArraySsel16, \
&PortPinArraySsel17, &PortPinArraySsel18};
slaveSelectPortPinArrayPointerArray *WuyinsSpi1SselPortPinArrayPointerArrayArrayV094[] = \
{&WuyinsSpi0SselPortPinArrayPointerArrayV092, \
&WuyinsSpi0SselPortPinArrayPointerArrayV092};
// typedef int portPinArray[2];
// typedef portPinArray *portPinArrayPointerArray[MAX_DEVICE_NUMBER];
// typedef portPinArray *slaveSelectPortPinArrayPointerArray[MAX_SLAVE_SELECT_NUMBER];
slaveSelectPortPinArrayPointerArray *WuyinsSpi0SselPortPinArrayPointerArrayV095[] = \
{&PortPinArraySsel00, &PortPinArraySsel01, &PortPinArraySsel02, \
&PortPinArraySsel03, &PortPinArraySsel04, &PortPinArraySsel05, \
&PortPinArraySsel06, &PortPinArraySsel07, &PortPinArraySsel08};
slaveSelectPortPinArrayPointerArray *WuyinsSpi1SselPortPinArrayPointerArrayV095[] = \
{&PortPinArraySsel10, &PortPinArraySsel11, &PortPinArraySsel12, \
&PortPinArraySsel13, &PortPinArraySsel14, &PortPinArraySsel15, \
&PortPinArraySsel16, &PortPinArraySsel17, &PortPinArraySsel18};
slaveSelectPortPinArrayPointerArray *WuyinsSpiSselPortPinArrayPointerArrayArrayV095[] = \
{&WuyinsSpi0SselPortPinArrayPointerArrayV092, \
&WuyinsSpi0SselPortPinArrayPointerArrayV092};
// ***************************************************************************
// SPI Functions
// ***************************************************************************
void setupAllSlaveSelectPortV095(portPinArrayPointerArray *slaveSelectPortPinArraryPointerArray[])
{
uint8_t i;
for (i = 0; i < SPI_SLAVE_SELECT_TOTAL; i++)
{
setupSpiSlaveSelectPortV0905(slaveSelectPortPinArraryPointerArray, i);
}
}
void setupSpiSlaveSelectPortV0905(portPinArrayPointerArray *slaveSelectPortPinArraryPointerArray[], \
uint8_t slaveSelectNumber)
{
// printf("Slave Select = %2d ", slaveSelectNumber);
initializeOutputPin01HighV093(slaveSelectPortPinArraryPointerArray[slaveSelectNumber]);
}
void setupAllSpiChannelV090()
{
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);
}
void setupOneSpiChannel080(uint8_t spiChannelNumber)
{
// printf("\nSPI Channel number = %01d", spiChannelNumber);
if (spiChannelNumber == 0)
{
// 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_PIO0_6, DISABLE); // Select P06, BUT disable
// 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);
}
else // (if spiChannelNumber == 1)
{
// Enable SSP1 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP1, ENABLE);
// Reset SSP1 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP1, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP1, DISABLE);
SYSCON_SetSPI1ClockDiv(10);
// No need to assign GPIO pins for SPI1, just disable
SSP_SSP1PinsInit(DISABLE); // disable SSEL
// Note: A bug!!! in Coocox lpc11xx_iocon.c v1.0 26Jan2010
// IOCON_SetPinFunc(IOCON_PIO2_2, PIO2_2_FUN_MISO1);
// IOCON_SetPinFunc(IOCON_PIO2_3, PIO2_3_FUN_PIO_MOSI1);
// IOCON_SetPinFunc(IOCON_PIO2_1, PIO2_1_FUN_SCK1);
// if(useSSEL == ENABLE) {
// IOCON_SetPinFunc(IOCON_PIO2_0, PIO2_0_FUN_SSEL1);
// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP1, &SSP_ConfigStruct);
// Enable SSP1 peripheral
SSP_Cmd(LPC_SSP1, ENABLE);
}
}
void setupAllSlaveSelectPortV090(portPinArrayPointerArray *slaveSelectPortPinArraryPointerArray[])
{
uint8_t i;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
setupSpiSlaveSelectPortV090(slaveSelectPortPinArraryPointerArray, i);
}
}
void setupSpiSlaveSelectPortV090(portPinArrayPointerArray *slaveSelectPortPinArraryPointerArray[], \
uint8_t slaveSelectNumber)
{
// printf("Slave Select = %2d ", slaveSelectNumber);
initializeOutputPin01HighV093(slaveSelectPortPinArraryPointerArray[slaveSelectNumber]);
}
void spiTransmit0901(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
portPinArrayPointerArray *slaveSelectPortPinArraryPointerArray[], \
SSP_DATA_SETUP_Type xferConfig)
{
setGpioDataPinLow01(slaveSelectPortPinArraryPointerArray[slaveSelectNumber]);
if (spiChannelNumber == 0)
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
else // (spiChannelNumber == 1)
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(slaveSelectPortPinArraryPointerArray[slaveSelectNumber]);
}
// ***************************************************************************
// End
// ***************************************************************************
// ***************************************************************************
// Function - Setup SPI slave select ports
// Date - 2013nov21
// ***************************************************************************
void setupSpiSlaveSelectPort(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
// printf("setupSpiSlaveSelectPort = %2d,%2d ", spiChannelNumber, slaveSelectNumber);
initializeOutputPin01High(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}
void setupAllSpiChannelSlaveSelectPorts080(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber)
{
uint8_t i;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
setupSpiSlaveSelectPort(portPinArraryPointerArrayArray, spiChannelNumber, i);
}
}
void setupAllSpiChannelsAndSlaveSelectPorts(portPinArrayPointerArray portPinArraryPointerArrayArray[])
{
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);
setupAllSpiChannelSlaveSelectPorts080(portPinArraryPointerArrayArray, SPI_CHANNEL_0);
setupAllSpiChannelSlaveSelectPorts080(portPinArraryPointerArrayArray, SPI_CHANNEL_1);
}
// ***************************************************************************
// Function - SPI transmit functions
// Date - 2013nov21
// ***************************************************************************
void spiTransmit082(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
SSP_DATA_SETUP_Type xferConfig)
{
setGpioDataPinLow01(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
if (spiChannelNumber == 0)
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
else // (spiChannelNumber == 1)
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}
// ***************************************************************************
// Function - SPI loop back test
// Date - 2013nov21
// ***************************************************************************
void spiLoopBack082(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
// *** Setup transfer buffers TxBuf, RxBuf ***
#define BUFFER_SIZE 2
uint8_t TxBuf[BUFFER_SIZE];
uint8_t RxBuf[BUFFER_SIZE];
uint8_t TxBuf0[BUFFER_SIZE]; // to store init data for printing
uint8_t RxBuf0[BUFFER_SIZE]; // to store init data for printing
// *** Setup xferConfig ***
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = (void*)TxBuf;
xferConfig.rx_data = (void*)RxBuf;
xferConfig.length = BUFFER_SIZE;
// *** Initialize transfer buffers ***************************************
TxBuf[0] = 0x55;
TxBuf[1] = 0xaa;
RxBuf[0] = 0x00;
RxBuf[1] = 0x00;
memcpy(TxBuf0, TxBuf, BUFFER_SIZE); // store init values
memcpy(RxBuf0, RxBuf, BUFFER_SIZE); // store init values
// *** SPI Transfer ***
spiTransmit082(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, xferConfig);
// *** Print results *****************************************************
/*
printf("\n*** Tx Rx buffer contents before transfer *** \n\n");
printf("Index 0 1 \n\n");
printf("%02x %02x \n", TxBuf0[0], TxBuf0[1]);
printf("%02x %02x \n", RxBuf0[0], RxBuf0[1]);
printf("\n*** Tx Rx buffer contents after transfer *** \n\n");
printf("Index 0 1 \n\n");
printf("%02x %02x \n", TxBuf[0], TxBuf[1]);
printf("%02x %02x \n", RxBuf[0], RxBuf[1]);
*/
// *** Debug only !!! ***
printf("\n*** Now looping SPI transfers every mS *** \n\n");
uint8_t i;
for (i = 0; i < 2; i++)
{
spiTransmit082(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, xferConfig);
delayMilliSecond(1);
}
}
// ***************************************************************************
// Function - Test SPI loopig back
// Date - 2013nov21
// ***************************************************************************
void testSpiLoopBack01()
{
// *** Set up SPI channel and slave select port ***
/*
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);
setupAllSpiChannelSlaveSelectPorts080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0);
setupAllSpiChannelSlaveSelectPorts080(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_1);
*/
setupAllSpiChannelsAndSlaveSelectPorts(Olimex20SlaveSelectPortPinArrayPointerArrayArray);
while (1)
{
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_0);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_1);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_2);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_3);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_5);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_6);
spiLoopBack082(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
SPI_CHANNEL_0, SLAVE_SELECT_4);
}
}
// ***************************************************************************
// Function - Test SPI0 SSEL pins
// Notes - Use a scope to display the waveform of each blinking ssel pin
// Date - 2013nov21
// ***************************************************************************
void blinkSpiSlaveSelectPort(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
int onMilliSecond, int offMilliSecond, int blinkCount)
{
blinkOneLed080(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber], \
onMilliSecond, offMilliSecond, blinkCount);
}
void testSpiSselPin0801()
{
initializeOutputPin01High(PortPinArrayP02);
initializeOutputPin01High(PortPinArrayP30);
initializeOutputPin01High(PortPinArrayP31);
initializeOutputPin01High(PortPinArrayP32);
initializeOutputPin01High(PortPinArrayP33);
initializeOutputPin01High(PortPinArrayP26);
initializeOutputPin01High(PortPinArrayP27);
uint8_t i;
for (i = 0; i < 10000; i++)
{
blinkOneLed080(PortPinArrayP02, 1, 1, 200);
blinkOneLed080(PortPinArrayP30, 1, 1, 200);
blinkOneLed080(PortPinArrayP31, 1, 1, 200);
blinkOneLed080(PortPinArrayP32, 1, 1, 200);
blinkOneLed080(PortPinArrayP33, 1, 1, 200);
blinkOneLed080(PortPinArrayP26, 1, 1, 200);
blinkOneLed080(PortPinArrayP27, 1, 1, 200);
}
}
void testSpiSselPin0802()
{
uint8_t i, j;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
initializeOutputPin01High(Olimex2SlaveSelectPortPinArrayPointerArray0[i]);
}
for (i = 0; i < 10000; i++)
{
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
blinkOneLed080(Olimex2SlaveSelectPortPinArrayPointerArray0[i], 1, 1, 200);
}
}
}
void testSpiSselPin0803()
{
uint8_t i, j;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
initializeOutputPin01High(Olimex20SlaveSelectPortPinArrayPointerArrayArray[0][i]);
}
for (i = 0; i < 10000; i++)
{
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
blinkOneLed080(Olimex20SlaveSelectPortPinArrayPointerArrayArray[0][i], 1, 1, 200);
}
}
}
void testSpiSselPin0804(portPinArrayPointerArray portPinArraryPointerArrayArray[])
{
uint8_t i, j;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
initializeOutputPin01High(portPinArraryPointerArrayArray[0][i]);
}
for (i = 0; i < 10000; i++)
{
// for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
for (i = 0; i < 4; i++)
{
blinkOneLed080(portPinArraryPointerArrayArray[0][i], 1, 1, 200);
}
}
}
void testSpiSselPin0805(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
uint8_t onMilliSecond, uint8_t offMilliSecond, uint8_t blinkCount)
{
setupSpiSlaveSelectPort(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber);
blinkSpiSlaveSelectPort(portPinArraryPointerArrayArray, \
spiChannelNumber, slaveSelectNumber, onMilliSecond, offMilliSecond, blinkCount);
}
testSpiSselPin0806() // blink SPI channel 0, slave select pins 1 to 6
{
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_1, 500, 500, 1);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_2, 500, 500, 2);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_3, 500, 500, 3);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_4, 500, 500, 4);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_5, 500, 500, 5);
testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, SPI_CHANNEL_0, \
SLAVE_SELECT_6, 500, 500, 6);
}
// ***************************************************************************
// End
// ***************************************************************************
// ***************************************************************************
// Old functions
// ***************************************************************************
void setupOneSpiSlaveSelect081(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
// portPinArray *slaveSelectPortPinArrayPointer;
// slaveSelectPortPinArrayPointer = SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber];
// printf("\nslaveSelectPortPinArray Port = %02d \n", (*slaveSelectPortPinArrayPointer)[PORT_INDEX]);
// printf("slaveSelectPortPinArray Pin = %02d \n", (*slaveSelectPortPinArrayPointer)[PIN_INDEX]);
// setupGpioPinOutputHigh050(*slaveSelectPortPinArrayPointer);
// printf("\nPortPinArray Port = %1d ", (*(SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]))[PORT_INDEX]);
// printf("PortPinArray Pin = %01d \n", (*(SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]))[PIN_INDEX]);
// printf("Port = %1d, %1d", \
// (*(Olimex2SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]))[PORT_INDEX], \
// (*(Olimex2SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]))[PIN_INDEX]);
setupGpioPinOutputHigh050(*(Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]));
}
void setupOneSpiSlaveSelect080(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
// portPinArray *slaveSelectPortPinArrayPointer;
// slaveSelectPortPinArrayPointer = SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber];
// printf("\nslaveSelectPortPinArray Port = %02d \n", (*slaveSelectPortPinArrayPointer)[PORT_INDEX]);
// printf("slaveSelectPortPinArray Pin = %02d \n", (*slaveSelectPortPinArrayPointer)[PIN_INDEX]);
// setupGpioPinOutputHigh050(*slaveSelectPortPinArrayPointer);
// printf("\nPortPinArray Port = %1d ", (*(SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]))[PORT_INDEX]);
// printf("PortPinArray Pin = %01d \n", (*(SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]))[PIN_INDEX]);
// printf("Port = %1d, %1d", \
// (*(Olimex2SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]))[PORT_INDEX], \
// (*(Olimex2SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]))[PIN_INDEX]);
setupGpioPinOutputHigh050(*(Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]));
}
void setupAllSpiSlaveSelect082(uint8_t spiChannelNumber)
{
uint8_t i;
for (i = 0; i < MAX_SPI_SLAVE_SELECT_NUMBER; i++)
{
setupGpioPinOutputHigh050(Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][i]);
}
}
void setupAllSpiSlaveSelect081(uint8_t spiChannelNumber)
{
uint8_t i;
printf("\nSetting up all SPI Slave Select ports");
i = 0;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 1;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 2;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 3;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 4;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 5;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i =6;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 7;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 8;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 9;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
i = 10;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect081(spiChannelNumber, i);
}
void setupAllSpiSlaveSelect080(uint8_t spiChannelNumber)
{
uint8_t i;
printf("\nSetting up all SPI Slave Select ports");
i = 0;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 1;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 2;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 3;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 4;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 5;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i =6;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 7;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 8;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 9;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
i = 10;
// printf("\nSPI = %1d, %1d ", spiChannelNumber, i);
setupOneSpiSlaveSelect080(spiChannelNumber, i);
}
void setupAllSpiChannelAndSlaveSelect080()
{
printf("\n\n*** Setting up all SPI Channels ***\n\n");
setupOneSpiChannel080(SPI_CHANNEL_0);
setupOneSpiChannel080(SPI_CHANNEL_1);
printf("\n\n*** Setting up all Slave Selects ***\n\n");
setupAllSpiSlaveSelect080(SPI_CHANNEL_0);
setupAllSpiSlaveSelect080(SPI_CHANNEL_1);
printf("\n\n*** End of Setting up ***\n\n");
}
void spiTransmit080(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
SSP_DATA_SETUP_Type xferConfig)
{
// portPinArray *slaveSelectPortPinArrayPointer;
// slaveSelectPortPinArrayPointer = Olimex2SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber];
if (spiChannelNumber == 0)
{
setGpioDataPinLow01(*Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(*Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}
else // (spiChannelNumber == 1)
{
setGpioDataPinLow01(*Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(*Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}
}
void spiTransmit081(uint8_t spiChannelNumber, portPinArray slaveSelectPortPinArrayPointer, \
SSP_DATA_SETUP_Type xferConfig)
{
setGpioDataPinLow01(slaveSelectPortPinArrayPointer);
if (spiChannelNumber == 0)
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
else // (spiChannelNumber == 1)
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(slaveSelectPortPinArrayPointer);
}
void spiLoopBack080(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
// *** Setup transfer buffers TxBuf, RxBuf ***
#define BUFFER_SIZE 2
uint8_t TxBuf[BUFFER_SIZE];
uint8_t RxBuf[BUFFER_SIZE];
uint8_t TxBuf0[BUFFER_SIZE]; // to store init data for printing
uint8_t RxBuf0[BUFFER_SIZE]; // to store init data for printing
// *** Setup xferConfig ***
SSP_DATA_SETUP_Type xferConfig;
xferConfig.tx_data = (void*)TxBuf;
xferConfig.rx_data = (void*)RxBuf;
xferConfig.length = BUFFER_SIZE;
// *** Initialize transfer buffers ***************************************
TxBuf[0] = 0x55;
TxBuf[1] = 0xaa;
RxBuf[0] = 0x00;
RxBuf[1] = 0x00;
memcpy(TxBuf0, TxBuf, BUFFER_SIZE); // store init values
memcpy(RxBuf0, RxBuf, BUFFER_SIZE); // store init values
// *** SPI Transfer ***
spiTransmit081(spiChannelNumber, PortPinArrayP10, xferConfig);
// *** Print results *****************************************************
printf("\n*** Tx Rx buffer contents before transfer *** \n\n");
printf("Index 0 1 \n\n");
printf("%02x %02x \n", TxBuf0[0], TxBuf0[1]);
printf("%02x %02x \n", RxBuf0[0], RxBuf0[1]);
printf("\n*** Tx Rx buffer contents after transfer *** \n\n");
printf("Index 0 1 \n\n");
printf("%02x %02x \n", TxBuf[0], TxBuf[1]);
printf("%02x %02x \n", RxBuf[0], RxBuf[1]);
// *** Debug only !!! ***
printf("\n*** Now looping SPI transfers every mS *** \n\n");
while (1)
{
spiTransmit081(spiChannelNumber, PortPinArrayP10, xferConfig);
delayMilliSecond(1);
}
}
// ***************************************************************************
// End
// ***************************************************************************
// ***************************************************************************
// Function - SPI transmit
// Date - 2013nov10
// ***************************************************************************
void spiTransmit060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
SSP_DATA_SETUP_Type xferConfig)
{
portPinArray *slaveSelectPortPinArrayPointer;
slaveSelectPortPinArrayPointer = Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber];
if (spiChannelNumber == 0)
{
setGpioDataPinLow01(*Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(*Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}
else // (spiChannelNumber == 1)
{
setGpioDataPinLow01(*Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(*Olimex20SlaveSelectPortPinArrayPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}
}
// ***********************************************************************
// End
// ***********************************************************************
void setupSpi051(int spiChannelNumber)
{
if (spiChannelNumber == 0)
{
// 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_PIO0_6, DISABLE); // Select P06, disable
// 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);
// Setup Ssel0
setupGpioPinOutputLow050(PortPinArraySsel0);
}
else // (if spiChannelNumber == 1)
{
// Enable SSP1 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP1, ENABLE);
// Reset SSP1 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP1, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP1, DISABLE);
SYSCON_SetSPI1ClockDiv(10);
// No need to assign GPIO pins for SPI1, just disable
SSP_SSP1PinsInit(DISABLE); // disable SSEL
// IOCON_SetPinFunc(IOCON_PIO2_2, PIO2_2_FUN_MISO1);
// IOCON_SetPinFunc(IOCON_PIO2_3, PIO2_3_FUN_PIO_MOSI1);
// IOCON_SetPinFunc(IOCON_PIO2_1, PIO2_1_FUN_SCK1);
// if(useSSEL == ENABLE) {
// IOCON_SetPinFunc(IOCON_PIO2_0, PIO2_0_FUN_SSEL1);
// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP1, &SSP_ConfigStruct);
// Enable SSP1 peripheral
SSP_Cmd(LPC_SSP1, ENABLE);
// Setup Ssel1
setupGpioPinOutputLow050(PortPinArraySsel1);
}
}
void setupXferConfig(SSP_DATA_SETUP_Type *xferConfigPointer, uint8_t digitControlRegisterBuffer[], \
uint8_t dummyReceiveBuffer[], uint8_t bufferSize)
{
xferConfigPointer->tx_data = digitControlRegisterBuffer;
xferConfigPointer->rx_data = dummyReceiveBuffer;
xferConfigPointer->length = bufferSize;
}
void SpiWriteRead050(SSP_DATA_SETUP_Type xferConfig, int spiChannelNumber)
{
if (spiChannelNumber == 0)
{
setGpioDataPinLow01(PortPinArraySsel0);
SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(PortPinArraySsel0);
}
else // (spiChannelNumber == 1)
{
setGpioDataPinLow01(PortPinArraySsel1);
SSP_ReadWrite(LPC_SSP1, &xferConfig, SSP_TRANSFER_POLLING);
setGpioDataPinHigh01(PortPinArraySsel1);
}
}
#endif /* SPI_HEADER_SEEN */
// ***********************************************************************
// End
// ***********************************************************************
.END
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment