Why I must set the Port P to output mode when I want use the SPI module?

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

Why I must set the Port P to output mode when I want use the SPI module?

1,605 次查看
xiangtailiang
Contributor I
I got a very magical problem that I can slove by myself.
I need your help...Thank you!
Device: 9S12XS128 80pin
IDE:   Codewarrior 5.0 
Problem:
When I use SPI Master mode,my initial code as below doesn't work:
  MODRR = 0x10; //spi use m4 m5 port
  (void)SPI0SR; /* Read the status register */
  (void)SPI0DRL;  /* Read the device register */ 
  SPI0CR1 = 0x50;
  SPI0CR2 = 0x08;
  SPI0BR = 0x01;
But when I set the Port P to output mode,just like this:
  DDRP=0XFF; //Set Port P to output mode               
  MODRR = 0x10; //spi use m4 m5 port
  (void)SPI0SR; /* Read the status register */
  (void)SPI0DRL;  /* Read the device register */ 
  SPI0CR1 = 0x50;
  SPI0CR2 = 0x08;
  SPI0BR = 0x01;
It can work very perfectly now.
What happen?Why I must set the Port P to output mode when I want use the SPI module?
标签 (1)
0 项奖励
回复
3 回复数

960 次查看
Lundin
Senior Contributor IV
Since you aren't setting SSOE in SPICR1, the MCU expects you to handle SS manually. If SS is an input, nothing will work as the slave will never get a chip select. Instead of setting DDRP, try setting SSOE.
0 项奖励
回复

960 次查看
xiangtailiang
Contributor I

Thanks for your help, I have try to set the SSOE in SPI0CR1. But it dosen't work.

 

0 项奖励
回复

960 次查看
Lundin
Senior Contributor IV
I just realized that you might have to set the MODFEN bit too to get it to work. But instead of relying on some stranger on a message board, I'd strongly recommend to read the register descriptions in the manual. :smileyhappy: Whether you can use SSOE or not depends on the device you are speaking with. You will have to check timing diagrams etc in the data sheet. I know there are many devices that are too slow to function with the SSOE feature.
0 项奖励
回复