kappa_am
Full Member level 6
Hi all,
I am planning to connect two dsPIC33ep512MU810 via SPI connection. The master works properly, but I cannot get any data in the buffer of slave one and it remains 0. I checked the clock pin chip selection pin using pin change interrupt, and they work properly. Even I disabled the SS, but still nothing. I don't know what I am missing. The program I wrote is rather large (multiple ADC with DMA, PWMs, etc) so I extract SPI section to avoid wasting your time. it is as below:
Osc configuration :
The configuration of master and slave is similar. I don't know what I have missed. I would be grateful if you give me a hint.
Thank you
I am planning to connect two dsPIC33ep512MU810 via SPI connection. The master works properly, but I cannot get any data in the buffer of slave one and it remains 0. I checked the clock pin chip selection pin using pin change interrupt, and they work properly. Even I disabled the SS, but still nothing. I don't know what I am missing. The program I wrote is rather large (multiple ADC with DMA, PWMs, etc) so I extract SPI section to avoid wasting your time. it is as below:
Code:
#include "Config.h"
unsigned short COMND, RAMP_SHAPE, LOP, FRQ_JMPN, SLP_CMP;
float FTHETA, DELTHETA;
volatile bit ACCDCC, ROT_DIR, REV, FRT_LOP, JMP_LOP, JMP_OC;
int* EXAM;
far unsigned int BUFF1A [4], BUFF1B[4], BUFF[2], BUFF2A[4], BUFF2B[4];
int* pv1;
unsigned int ReadWordArr[64];
unsigned int WriteWordArr[64];
void SPI4_INT() iv IVT_ADDR_SPI4INTERRUPT {
LATD=SPI4BUF; //
IFS7bits.SPI4IF=0;
}
void SPI4EER() iv IVT_ADDR_SPI4ERRINTERRUPT {
SPI4STATbits.SPIEN = 0; // Disable SPI module
SPI4STATbits.SPIROV=0; //Clear the Receive Overflow Flag
IFS7bits.SPI4EIF = 0; // Clear the SPI2 Error Interrupt Flag
SPI4STATbits.SPIEN = 1; // Enable SPI module
}
void CHNG() iv IVT_ADDR_CNINTERRUPT ics ICS_AUTO {
IFS1bits.CNIF = 0;
//LATD^=0xFFFF;
}
void main() {
IPC4=0x2000 |IPC4;
Osc_Config(140);
//////////////////////////////////////////////////////
ANSELB=0x0030;
TRISB=0x003C;
ANSELD= 0x0000;
TRISD = 0x0000;
ANSELG = 0x0000;
TRISG = 0x1000;
OSCCON=OSCCON & 0xFFDF; //Unlock I/O
RPINR31 = 0x227C; //RPI34=SCK, RPI124=SDI,
RPINR32= 0x0023; // RPI35=SS
RPOR15=0x0022; //RP126=SDO
OSCCON=OSCCON | 0x0020; //LOck I/O
CNENG.b12=1;
IFS1.b3=0;
IEC1.b3=1;
///////////////////////////////////////////////////////////////
SPI4BUF=0;
IFS7bits.SPI4EIF = 0; // Clear the Error Interrupt flag
IEC7bits.SPI4EIE = 0; // Enable the error interrupt
SPI4CON1=0x0500;
SPI4STATbits.SPIROV=0;
SPI4STAT=0x8000;
IFS7bits.SPI4EIF = 0;
IEC7bits.SPI4EIE = 1;
PMD3.b10=1;
////////////////////////////////////////////////////////////////
while (1) {
LATD=SPI4BUF;
Delay_us(10);
}}
Osc configuration :
Code:
void Osc_Config(unsigned int CLKFREQ) {
OSCCON=0x33E0;
CLKDIV=0x0006; //PLL's Divider Configuration (divided by CLKDIV<4:0>+2)
PLLFBD=(CLKFREQ-1)*2; //PLL's Feedback Congiguration (multiply by PLLFBD+2)
//OSCTUN=0;
//REFOCON=0;
ACLKCON3=0xE4A0; //Axuliary OSC PLL Configuration 0x00F0 post divider; 0x000F prescale
ACLKDIV3=7;}
The configuration of master and slave is similar. I don't know what I have missed. I would be grateful if you give me a hint.
Thank you