This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading SPI

Hi,

I've a pb using SPI on ST10F168.

sfr   SSCTB    = 0xF0B0;
sfr   SSCCON   = 0xFFB2;
sbit  SSCBSY   = SSCCON^12;
sfr   SSCRB    = 0xF0B2;
sfr   SSCBR    = 0xF0B4;
sbit  SSCEN    = SSCCON^15;

sfr   DP3      = 0xFFC6;
sfr   P3       = 0xFFC4;

sbit DirMRST	= DP3 ^ 8;
sbit MRST	= P3 ^ 8;
sbit DirMTSR	= DP3 ^ 9;
sbit MTSR	= P3 ^ 9;
sbit DirSCLK	= DP3 ^ 13;
sbit SCLK	= P3 ^ 13;


void SetSPI_Eeprom(void)
{
   	//Register in Control mode
	SSCEN = 0;
	//-- Set Master Data Out to 1
	MTSR = 1;
	//-- Set Master Data Out
	DirMTSR = 1;
	//-- Set Master Data In
	DirMRST = 0;
	//-- Set Master Clock to 1
	SCLK = 1;
	//-- Set Clock Out in Master
	DirSCLK = 1;

	//Init HW OK

	//Set BaudRate = fCPU/[2*(SSCBR+1)] = 24M/[2*(9+1)] = 1.2Mbaud
	SSCBR = 0x0009;
	SSCCON = 0x4057;

	//SSCEN : SSC enable
	SSCEN = 1;
}

static unsigned char RecDataSPI(void)
{
	SSCTB = 0x00;
	while(SSCBSY);
	return (unsigned char)(SSCRB&0x00FF);
}


After init the SPI calling SetSPI_Eeprom() function, I would to read in it using RecDataSPI() function.
But I noticed that the bit SSCBSY falls again too much early, data is bad. I replaced the while(SSCBSY); instruction by a manual temporization (Approximately 15 us), and I find well my data ! I does't understand why the bit of control SSCBSY does not work correctly for the reading SPI. Writing works OK.

Thanks in advance.
Regards,

Jean-Marc Moulinier

0