microchip - how to make spi connection between arduino uno and dspic33ep512mc502? -


  • i want test spi comunication between arduino uno , dspic33ep512mc502, use serial port see receiving data microcontroller; -arduino uno master -dspic33ep512mc502 slave

here code arduino uno :

#include<spi.h>  byte y=1; void setup() {  serial.begin(9600); spi.begin();  spi.setdatamode(spi_mode1);       digitalwrite(ss,high); // spi.setbitorder( lsbfirst);  spi.setbitorder( msbfirst); }  int trnasfer_spi(int d) { digitalwrite(ss,low);   byte r=spi.transfer(7);  digitalwrite(ss,high); return r;  }  void loop() {   if (serial.available() > 0) {      // read incoming byte:         int incomingbyte = serial.read();         y=trnasfer_spi(incomingbyte);          }         serial.print(y, dec); delay(1000);   } 

here dspic33ep512mc502 code(just spic comunication):

initialization :

anselbbits.ansb0 = 0;  trisbbits.trisb0 = 1;   trisbbits.trisb7 = 1;   trisbbits.trisb8 = 0;   trisbbits.trisb9 = 1;   spi1con1bits.dissck = 0; spi1con1bits.dissdo = 0;  spi1con1bits.mode16 = 0;  spi1con1bits.smp = 0;     spi1con1bits.ckp = 0;     spi1con1bits.cke = 1;     spi1con1bits.msten = 0;   spi1con1bits.ssen = 1;     //setari registru spi1stat spi1statbits.spirov = 0;  spi1statbits.spien  = 1;   ifs0bits.spi1if = 0;  iec0bits.spi1ie = 1;  ipc2bits.spi1ip = 6;  spi1buf =3;  

spi1interrupt:

 void __attribute__((__interrupt__)) _spi1interrupt(void)  {      ifs0bits.spi1if = 0;                spi1statbits.spirov = 0;            spi1buf=3;       }; 

i expect see value 3 on serial monitor, see value 7 or 255.

spi reads , writes @ same time, write register must followed read, otherwise next read won't work.

so try read spi1buf after writing it.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -