This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

spi testing in msc1210 y5

Hello Dear,

                      I have used MSC1210 controller but i have config spi but its working or not? tx and rx how to debug

i have attached code please give solution.

            #include <Reg1210.H>
#include <stdio.h>

//unsigned char data irqen_init _at_ 0x7f ; // image of PAI
#define FWVer 0x04
#define CONVERT 0
#define CLEAR 0

extern void autobaud(void);

 xdata char received_data[50];
void init_spi ();
void transmit_receive ();// interrupt 6;
void test_spi ();
void test_spi ()
{
SPIDATA = 55;
//while (1);
}
void setport (void)
{
P3DDRL &= 0xf0;
P3DDRL |= 0x07; //P30 input, P31 output
TF2 = CLEAR; T2 = CLEAR;
CKCON |= 0x20; // Set timer 2 to clk/4
RCAP2 = 0xffd9; //Set Timer 2 to Generate 57690 bps
//Initialize TH2:TL2 so that next clock generates first Baud Rate pulse
THL2=0xffff;
T2CON = 0x34; // Set T2 for Serial0 Tx/Rx baud generation
//SCON: Async mode 1, 8-bit UART, enable rcvr; TI=CLEAR, RI = CLEAR
SCON0 = 0x50;
PCON |= 0x80; // Set SMOD0 for 16X baud rate clock
}
void init_spi ()
{

    PDCON = 0x14;        // turn on ADC-Vref, SPI and Systimers
/*enable SPI, specify Master SPI and specify clock rate, (Fosc / 32)
and CPHA = 1*/
SPICON = 0x96;
/*Flush receive buffer, and set IRQ level to 2*/
SPIRCON = 0x81;
/*Flush transmit buffer, and set IRQ level to 4*/
SPITCON = 0x82;
/*buffer start address = 0x0ao, and end address = 0x0b0*/
SPISTART = 0x0a0;
//Serial Peripheral Interface (SPI)
//17-36
SPIEND = 0x0b0;
/*Master mode: set MISO for input, and MOSI, SS & SCK for strong outputs*/
P1DDRH = 0x75;
P1 |= 0xF0;
/*enable SPI interrupt*/
//PIREG |= 0x0c;
AISTAT |=0x0c;
IE |= 0x80;
//EPFI = 1;

}
void transmit_receive () interrupt 6 using 1
{

 xdata int i, k;//, p;
static xdata int j, l;

if (AISTAT & 0x08)
{/*Transmitter*/
j += 2; //set up value of j to be transmitted
SPIDATA = j; //transmit j. This actually goes to the circular buffer
AISTAT &= ~0x08; //clear SPI transmit interrupt flag
}




if (AISTAT & 0x04)
{/*Receiver*/
i = SPIRCON & 0x7F; //extract the count for the number of
AISTAT &= ~0x04; //deactivate SPI receive flag
if (l >= 50)
{
/*do not exceed the 50 received_data[] array limit*/
for (l = 0; l < 5; l++)
{
printf ("\n");
for (k = 0; k < 10; k++)
{
printf (" %c", received_data[k + l * 10] );
}
}
printf ("\n");
l=0; //reset the received_data[] array index.
}
for (k = 0; k < i; k++)
{
if (l >= 50)
break;
/*data received through the SPI channel is read at the SPIDATA SFR*/
received_data[l++] = SPIDATA; //keep track of received data
}
}
}
void main(void)
{
setport ();
//init_spi ();
//test_spi ();
//autobaud();
while(1)
{
test_spi ();
printf ("asd:\n");
}
}

Thanks,

Ramesh k