SPI reading issues
i have configured the spi in stm8l controller.I have attached the code below:
void SetupSPI()
{
PB_DDR |= BIT(6) | BIT(5) ; // mosi and sck as output.
PB_DDR &= ~BIT(7); // miso as input.
PB_CR1 |= BIT(7);
PB_CR1 |= BIT(6)| BIT(5) ; // mosi and **** as push pull state for spi
PB_CR2 |= BIT(6)| BIT(5); // enable fast mode
SPI1_CR1 = 0xBD; // Disable spi ,set clock phase and polarity,Capture LSB on first edge ,set baud_rate(fSYSCLK/64),configure as master
SPI1_CR2 = 0x03; // Enable 2-line unidirectional data mode ,full duplex mode,Software slave management,Internal slave select as master
SPI1_CR1 |= BIT(6); // Enable spi .
}
//Function to perform spi write
void Spi_write(char *address,int length)
{
int index;
int collect;
for(index=0 ; index < length ; index++)
{
SPI1_DR = *address++; // write data to be transmitted to the SPI data register
while(!(SPI1_SR & 0x02)); // wait until transmit complete
while(!(SPI1_SR & 0x01)); // wait until rx buffer loaded
collect = SPI1_DR; // Store received temporary data .
}
}
//Function to perform spi read
int Spi_read(int data_register)
{
int temp = 0;
SPI1_DR = 0x00 ; // Send over SPI to Slave
while(!(SPI1_SR & 0x02)); // TX buffer ready?
while(!(SPI1_SR & 0x01)); // RX Received?
temp = SPI1_DR ;
return temp; // Store received data
// *data_register++ = SPI1_DR ;
}
i verified the code by probing the mosi and clock during write operation and found it working properly, but reading deosnt seen to work.i confirmed the same by reading the manufacturing id of flash ic. Why is that so?Please share your suggestions about this issue.
