1) I have got a problem with ISP interrupt routine. MCU goes to interrupt routine even if theres no data being receieved.
2) And I am sending 1 byte data to the slave then the slave sends 4 byte response, so I miss 3 bytes. How can I get all the data, I want to do this in 8 bit data mode, if I use 16 bit mode then I will miss 2 byte.
void interrupt VectorNumber_Vspi0 SPI0_ISR (void) {
if(SPI0SR_SPIF==1){
gelen[gel]= SPI0DRL;
gel++;
if(gel==5){
gel=0;
}
}
}
void main(void)
{
/* PLL Configuration */
CPMUCLKS_PSTP = 0;
CPMUCLKS_PLLSEL = 1; /* Enable the PLL to allow write to divider registers */
CPMUSYNR = 0x58; /* Set the multiplier register */
CPMUPOSTDIV = 0x00; /* Set the post divider register */
CPMUPLL = 0x00; /* Set the PLL frequency modulation */
while(!CPMUFLG_LOCK) { /* Wait until the PLL is within the desired tolerance of the target frequency */
}
CPMUPROT=0x00; /* Enable protection of clock configuration registers */
DDR0AD=0xFF; //Analog ports output
DDR1AD=0xFF; //Analog ports output
/* Initialise the SPI */
SPI0CR2 = 0x10; /* 8-Bit transfer width; SS pin is used by the SPI */
SPI0BR = 0xAA; /* SPI clock = Bus Clock divided by 2048 = 15.625kHz */
SPI0CR1 = 0x56; /* SPI enabled; Master mode; Active high clocks; Slave Select output enabled*/
//SPI0CR1_CPOL =0; //SPI Clock Polarity Bit
SPI0CR2_XFRW =1;
SPI0CR1_LSBFE=0; //LSB
SPI0CR1_CPHA =0; //SPI Clock Phase Bit
// SPI0CR1_MSTR =0; //Slave mode
// SPI0CR1_SSOE =0; //Slave Select
SPI0CR1_SPIE =1; //SPI interrup enable bit
UART1_Init();
__asm CLI; //Enable interrupts globally
//send_string_1("Worked !!!\r\n");
}
for(;;)
{
while(SPI0SR_SPTEF==0); /* Wait till transmit Tx_Data register is empty */
SPI0DRL = 0x00; /* Write Tx_Data to transmit Tx_Data register */
/* Writing SPIDR after reading SPISR with SPTEF=1 clears SPTEF */
put_char_1(gelen[i]);
i++;
put_char_1(gelen[i]);
i++;
put_char_1(gelen[i]);
i++;
put_char_1(gelen[i]);
i++;
put_char_1(gelen[i]);
i=0;
/* Delay to seperate SPI transmissions */
for (dummy_counter_1 = 0; dummy_counter_1 < 100; dummy_counter_1++)
{
for (dummy_counter_2 = 0; dummy_counter_2 < 100; dummy_counter_2++)
{ ;
}
}
}
}