S12 SPI read and write 93lc76c

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

S12 SPI read and write 93lc76c

跳至解决方案
2,716 次查看
xiaolin_gao
Contributor I

hi all, 

 

How to clear SPISR_SPTEF bit?

 

 DATASHHET the following description:

 

 If set, this bit indicates that the transmit data register is empty. To clear
this bit and place data into the transmit data register, SPISR has to be read with SPTEF = 1, followed by a write
to SPIDR. Any write to the SPI Data Register without reading SPTEF = 1, is effectively ignored.

 

Can provide some routine? thank you!

标签 (1)
0 项奖励
回复
1 解答
923 次查看
bigmac
Specialist III

Hello,

 

When processing a single byte at a time, such as with the previous code snippet, the period that SPTEF flag remains low will be very short, typically a few bus cycles only.  During debug, it is therefore unlikely  that you would ever observe the flag being cleared.

 

However, you should not single step through the function for another reason.  The monitoring of the SPISR and SPIDR registers by the debugger can inadvertently cause the SPIF flag to be cleared prior to  the wait loop being exited.  The function will then never exit.

 

Regards,

Mac

 

在原帖中查看解决方案

0 项奖励
回复
4 回复数
923 次查看
xiaolin_gao
Contributor I

hi mac,

i use oscilloscope track mosi pin and observe the data had outed after "SPIDR = value",:smileyhappy:

thank you,mac:smileyvery-happy:.

0 项奖励
回复
923 次查看
bigmac
Specialist III

Hello,

 

The SPTEF flag will be cleared and will then become set during the normal course of sending a byte.  You need to test the flag, to make sure it is set, prior to sending each byte.  More important is the clearing of the SPIF flag following the completion of each byte transfer.  The following code would be typical for the transfer of a single byte in both directions.

 

byte SPI_trans( byte value)

{

   while ((SPISR & 0x20) == 0);  // Wait until SPTEF flag is set

   SPIDR = value;

   while ((SPISR & 0x80) == 0);  // Wait until SPIF flag is set

   return SPIDR;                 // Also clears flag

}

 

Regards,

Mac

 

0 项奖励
回复
923 次查看
xiaolin_gao
Contributor I

hi mac,

 

 

thank your routine,but the SPTEF is not change too?
Message Edited by xiaolin.gao on 2009-07-08 10:52 PM
0 项奖励
回复
924 次查看
bigmac
Specialist III

Hello,

 

When processing a single byte at a time, such as with the previous code snippet, the period that SPTEF flag remains low will be very short, typically a few bus cycles only.  During debug, it is therefore unlikely  that you would ever observe the flag being cleared.

 

However, you should not single step through the function for another reason.  The monitoring of the SPISR and SPIDR registers by the debugger can inadvertently cause the SPIF flag to be cleared prior to  the wait loop being exited.  The function will then never exit.

 

Regards,

Mac

 

0 项奖励
回复