S12 SPI read and write 93lc76c

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S12 SPI read and write 93lc76c

ソリューションへジャンプ
2,500件の閲覧回数
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 解決策
707件の閲覧回数
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 返答(返信)
707件の閲覧回数
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 件の賞賛
返信
707件の閲覧回数
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 件の賞賛
返信
707件の閲覧回数
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 件の賞賛
返信
708件の閲覧回数
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 件の賞賛
返信