SPI Slave questions

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

SPI Slave questions

跳至解决方案
2,632 次查看
carlosomarharoc
Contributor II

Hello! Freescale community

 

I'm learning about SPI and how use the registers.

 

I have initialized the module as slave mode

I suppose when the master wants communicate with the slave, the slave will get the data via interrupt.

 

My question is.  When the microprocessor get in the Vspir  interrupt, he can send information to the master?

 

the other question is if i have wrote well  the interrupt code for the slave. (code below)

interrupt VectorNumber_Vspi void Vspi_ISR (void) {     byte data;                 while (!SPIS_SPRF){};  // Wait until the next byte is received      data = SPID;     pixels[0]=data; }

 

Regards!

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
2,054 次查看
david_diaz
NXP Employee
NXP Employee

Hello Carlos Omar,

The following figure shows the SPI modules of two MCUs connected in a master-slave arrangement.

During a transfer, the master shifts data out (on the MOSI pin) to the slave while simultaneously shifting data in (on the MISO pin) from the slave. The transfer effectively exchanges the data that was in the SPI shift registers of the two SPI systems.

spi.JPG.jpg

After this exchange of data, an interrupt may be generated.

Regarding your code, I would like to recommend you a Peripheral Module Quick Reference in which you can find more information and sample code about the SPI Module in the S08 family.


Please find the document mentioned in the following link:

http://www.freescale.com/files/microcontrollers/doc/user_guide/HCS08QRUG.pdf

Hope this information will be useful for you.


Have a good day.


Best Regards,

David Diaz


-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
4 回复数
2,055 次查看
david_diaz
NXP Employee
NXP Employee

Hello Carlos Omar,

The following figure shows the SPI modules of two MCUs connected in a master-slave arrangement.

During a transfer, the master shifts data out (on the MOSI pin) to the slave while simultaneously shifting data in (on the MISO pin) from the slave. The transfer effectively exchanges the data that was in the SPI shift registers of the two SPI systems.

spi.JPG.jpg

After this exchange of data, an interrupt may be generated.

Regarding your code, I would like to recommend you a Peripheral Module Quick Reference in which you can find more information and sample code about the SPI Module in the S08 family.


Please find the document mentioned in the following link:

http://www.freescale.com/files/microcontrollers/doc/user_guide/HCS08QRUG.pdf

Hope this information will be useful for you.


Have a good day.


Best Regards,

David Diaz


-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
2,055 次查看
carlosomarharoc
Contributor II

Hello David, Thanks for reply.

Now my SPI Master-Slave  works in  9S08AC60.

I was trying Master-Master(fault mode). But i think that arrangement is imposible. When I debug it  the Master with fault mode  always stays in slave mode.

But my code in master-slave works now, thanks alot.

According to my fault mode code is  the next.

void SPI_Init_Mstr_F(void)

{

  PTEDD_PTEDD4=1; //Initializate pin (SS) like GPIO as input

  PTED_PTED4=1; //No activity on SPI

  SPI1C1=0xD0; /*Set SPI in master mode, active in High, first edge on clock source,

  start data on least significant bit,enables the interrupts generated

  by the SPRF,MODF and SS input for mode fault*/

  SPI1C2=0x10; //Fault mode enable, "NO" Bidirectional

  SPI1BR=0x65; /*Baud rate to 8928.57  Baud rate formule:  

  Baud rate = Busclock/((Prescale Divisor)(Rate Divisor))*/

}

interrupt VectorNumber_Vspi1 void Vspi1_isr_MODF(void) // This Responds to “faul mode error” interrupt

{

  while (!SPI1S_MODF){}; //wait for faul mode error

  // Write your code here  before writing to SPI1C1 register

  while (!SPI1S_SPRF){};   //Wait until the next byte is received   

     PTFD = SPI1D; //Save the data of the buffer

     PTED_PTED4=1;   

   

  temp=SPI1S_MODF;

  SPI1C1=0xD0; //Set SPI in master mode, active in High, first edge on clock source,

  //start data on least significant bit,enables the interrupts generated

  //by the SPRF,MODF and SS input for mode fault

  SPI1C2=0x10; //Fault mode enable, "NO" Bidirectional

}

I was looking for mode fault examples. In the document that you mentioned dont have example of fault mode

0 项奖励
回复
2,055 次查看
TICS_Fiona
NXP Employee
NXP Employee

What is the part number of your MCU or Processor?

0 项奖励
回复
2,055 次查看
carlosomarharoc
Contributor II

MC9S08MP16

0 项奖励
回复