In my application, Main is an opcode handler which calls one of 10 functions based on a serial 0 opcode recieved. Main also defines an u_char InputArray[4] = {0xE2,0xFF,0xAA, 0xCC). One of the Opcodes calls a function which takes as an argument, a pointer to the above array. The function is supposed to send the 4 values in the array over the SPI as a master. What comes out instead is -> 0xE2, 0xAA, 0xCC, 0xCC. Here is the pertinent part of MAIN and the SPI handler function:
******************************************************************************/ #define _MSC1210_Recieve_ /***************************************************************************** Include */ #include "MSC1210_SPI.h" /***************************************************************************** Defines */ /***************************************************************************** Globals */ /***************************************************************************** Prototypes */ // Function Prototypes in MSC1210_SPI.h /***************************************************************************** MSC1210_SPI */ extern void MSC1210_SPI(unsigned char * pArrayStart) { ES = 0; // Disable Serial0 Interrupts P1DDRH = 0x75; // P1.4,5,7 = output; P1.6 = input PDCON &= 0xFE; // Turn on SPI SPIInit(); SPIDATA = *pArrayStart++; SPIDATA = *pArrayStart++; SPIDATA = *pArrayStart++; SPIDATA = *pArrayStart; while((AIE&0x04)!=0x04) { ;//Nothing, wait for SPIrx } PDCON ^= 0x01; // Turn off SPI ES = 1; }/* MSC1210_SPI */ /***************************************************************************** Functions */ // Function: SPIInit(void) // // Description: Setup portions of the SPI interface // which will not change when using different // Port1 functions // void SPIInit(void) { unsigned char data ClearFlags = 0x00; //SPICON -> 111x0110 = tclk/256,FIFO on, MSB first, Master, Valid on Edge, Idle Low SCLK SPIDATA = ClearFlags; ClearFlags = SPIDATA; SPICON = 0xF6; SPIRCON = 0x82; // Flush RXbuffer, 4 byte int SPITCON = 0xAA; // Flush TXbuffer, set SCLK drive, 4 byte int SPISTART = 0x00; SPIEND = 0x04; }/* SPIInit */ //############################################################################################## //############################################################################################## /***************************************************************************** Globals */ unsigned char data OpCode = 0x00; bit ChangeOp = 1; /***************************************************************************** Prototypes */ // Contained in MSC1210_MAIN.h /***************************************************************************** MAIN */ void MAIN(void) { static unsigned char data InputArray[] = {0xE2,0xF0,0xAA,0xCC}; const unsigned char data * pArray = &InputArray[0]; CKCON &= 0xf8; // 0 MOVX cycle stretch, timer1 clk/4, timer0 = clk/12 USEC= 10; // 11.8MHz Clock MSECH=0x07; // one millisecond high HMSEC=0x63; // one hundred millisecond interrupt MSC1210_Startup(); // Some basic Starup Initialization TI_0 = 0; EA = 1; // Enable Global Int while(1) // EOS Super Loop { // Running the Serial Interupt Opcode Handler switch(OpCode) { . . case 0x37: // "7" ChangeOp = 1; MSC1210_SPI(pArray); OpCode = 0x00; break; . . default: break; } }