S12xDP512 SPI problem

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

S12xDP512 SPI problem

2,481 次查看
Tricky
Contributor I
Hi,
 
I am trying to communicate with a MAX7219 over spi from the above CPU with a 16bit transfer.
 
The 7219 nees the /SS pin to go high after the 16th bit to latch the data, for this reason i cannot use the /SS pin under cpu control.
 
I am now trying to manually set the /SS port pin with the following code. The /SS is set to an output.
 
 //SPI Setup - Done at startup
 SPI0CR1 = 0x50;
 SPI0CR2 = 0x00;
 SPI0BR = 0x05;
 
// Spi TX function
 U8 i = 0
 
// Select the 7129
 DioROT6.Bits.LED_CS = 0;   
 
 // Send Data
  for(i = 0; i < 2;i ++)
  {
    SPI0DR = 0x0B;
    while(!(SPI0SR & 0x20));
  }  
  
// Deslect the 7219
 DioROT6.Bits.LED_CS = 1; 
 
But for some reason the /SS port pin is going hi (deselecting) after the first byte has been sent. It would appear that the second test if the tx buffer is empty is not working.
 
Can anyone see why this would be the case or what i could be doing wrong?
 
Regards
R
标签 (1)
0 项奖励
回复
4 回复数

1,173 次查看
Tricky
Contributor I
Hi Mac,
 
Thank you very much. That has sorted out the problem and all is working fine.
 
Thank you again.

Regards
 
Richard
0 项奖励
回复

1,173 次查看
bigmac
Specialist III
Hello R,
 
I think your problem is that you wait for the transmit buffer to empty for each byte, but you do not wait until the second byte has actually been transmitted, before raising the /SS signal.  To do this, you should monitor the SPI (receive) flag, and wait until it is set, to ensure that the returned byte is complete, and hence the forward transmission is also complete.
 
You might place the following line immediately after the for loop exits -
 
while(!(SPI0SR & 0x80));
 
You will also need to read the SPI0DR register in order to clear the flag.
 
Regards,
Mac
0 项奖励
回复

1,173 次查看
Tricky
Contributor I
Hi Mac,
 
Many thanks for your reply.
 
I am not actually reciving any byte back from the device i am only sending it data.
 
Is there anyway to know i have actually sent the second byte sucessfully without recieving a byte back?
 
Regards

Richard
0 项奖励
回复

1,173 次查看
bigmac
Specialist III
Hello R,
 
The SPI flag will become set after eight clock pulses have been generated by the master (the MCU).  It does not matter whether or not you are using the return data from the slave.
 
Regards,
Mac
 
0 项奖励
回复