Go Down

Topic: [SPI] DUE as SPI Slave (Read 459 times) previous topic - next topic

sketchgger

Hey guys,

While I did managed to get the DUE configured as a Slave, the code is behaving chaotically - in the sense that it works perfectly for 15 seconds, after which the data on the MISO line gets distorted

What i mean by distorted is that I do write 0x4AD3 in the TD register, but on the oscilloscope I see something like 0xAD34. Any thoughts?


Code: [Select]

void setup()
{
  SPI.begin(ChipSelectPin);
 
  //Change the SPI Write Protection Mode Register
  //with the key and the Write Protection disable
  REG_SPI0_WPMR=0x53504900;

  REG_SPI0_MR = (0 << SPI_MR_MSTR);
 
  //SPI enable
  REG_SPI0_CR=0x1;
 
  //Changes the SPI clock and the number of bits transferred
  SPI0->SPI_CSR[0]=0x00000B80;
}

  //wait for a valid reception: SR & SR_RDRF (Receive Data Register Full) will be set to 1
  while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0)
    ;
  int16_t d = SPI0->SPI_RDR & 0x0000FFFF;

  //send a response: TDR(Transmit Data Register)
  while ((SPI0->SPI_SR & SPI_SR_TDRE) == 0)
    ;
  SPI0->SPI_TDR = 0x1234 | SPI_PCS(10);// on the oscilloscope, on the MOSI line  I get 0x4123;

ard_newbie


Go Up