2013-11-21

SPI testing notes


// ***************************************************************************
// Program  - Fong EKG v5.09
// Function - Testing Olimex EKG
// Author   - TL Fong
// Build    - 2013.11.21.01
// Date     - 2013nov21hkt1451
// 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()
{
testSpiSselPin();
}

// ***************************************************************************
// End
// ***************************************************************************



// ***********************************************************************
// test050.h 2013nov21hkt1451
// ***********************************************************************

#include "led050.h"
#include "key050.h"
#include "spi050.h"
#include "adc050.h"
#include "eeprom050.h"
#include "mled050.h"
#include "spi080.h"

void testSpiSselPin()
{
// testSpiSselPin0801();
// testSpiSselPin0802();
// testSpiSselPin0803();
// testSpiSselPin0804(Olimex20SlaveSelectPortPinArrayPointerArrayArray);
// testSpiSselPin0805(Olimex20SlaveSelectPortPinArrayPointerArrayArray, \
                  // SPI_CHANNEL_0, SLAVE_SELECT_3, 200, 500, 4);
    testSpiSselPin0806();
}

// ***************************************************************************
// End
// ***************************************************************************



// ***********************************************************************
// spi080.h 2013nov21hkt1451
// ***********************************************************************

#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 7

#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

// *** 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 PortPinArraySsel10 = {PORT2, PIN0};
portPinArray PortPinArraySsel11 = {PORT2, PIN0};
portPinArray PortPinArraySsel12 = {PORT2, PIN0};
portPinArray PortPinArraySsel13 = {PORT2, PIN0};
portPinArray PortPinArraySsel14 = {PORT2, PIN0};
portPinArray PortPinArraySsel15 = {PORT2, PIN0};
portPinArray PortPinArraySsel16 = {PORT2, PIN0};

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};


// ***************************************************************************
// Function - Test SPI0 SSEL pins
// Notes    - Use a scope to display the waveform of each blinkig ssel pin
// Date     - 2013nov21
// ***************************************************************************
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);
}


void setupSpiSlaveSelectPort(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                             uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
initializeOutputPin01High(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber]);
}

void blinkSpiSlaveSelectPort(portPinArrayPointerArray portPinArraryPointerArrayArray[], \
                             uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                             int onMilliSecond, int offMilliSecond, int blinkCount)
{
blinkOneLed080(portPinArraryPointerArrayArray[spiChannelNumber][slaveSelectNumber], \
     onMilliSecond, offMilliSecond, blinkCount);
}


// ***************************************************************************
// End
// ***************************************************************************

.END



No comments:

Post a Comment