• AVR Freaks

Hot!DSPIC33EP128GM306

Author
delmat
New Member
  • Total Posts : 29
  • Reward points : 0
  • Joined: 2018/08/01 09:53:05
  • Location: 0
  • Status: offline
2019/08/20 06:55:22 (permalink)
0

DSPIC33EP128GM306

Dear All,
 
I'm not able to communicate with an SPI device. I'm using a DSPIC33EP as master and for now I'm trying to read and write with SPI some data.
 
I've verified the correct writing with SPI but I'm stuck with reading some values.
In particuar I'm testing SPI with the SDO pin connected to the SDI pin.  Essentially, I should read what I'm writing.
With the oscilloscope I've verified the correct writing but when I print (via UART) the read data I always se 0x00 value.
 
Here is my code:
 
SPI initialization
 
 
void SPI1_Initialize (void)
{
    
        // setup the SPI peripheral
    SPI1STAT = 0x0; // disable the SPI module (just in case)
    SPI1CON1 = 0x0161; // FRAMEN = 0, SPIFSD = 0, DISSDO = 0, MODE16 = 0; SMP = 0; CKP = 1; CKE = 1; SSEN = 0; MSTEN = 1; SPRE = 0b000, PPRE = 0b01
    SPI1CON1bits.CKE = 0x01;
    SPI1CON1bits.CKP = 0x00;
    SPI1STAT = 0x8000; // enable the SPI module
}

 
and main code
 

int main(void)
{
   // initialize the device
   SYSTEM_Initialize();
   while (1)
   {
      char temp;
      temp=SPI1_Exchange8bit('U');
      Delay_us(100000);
      OUT_11_ON;
      UART1_Write(temp);
   }
   return 1;
}

 
do you have any suggestion in order to solve the problem?
 
Best Regards,
 
Mattia
#1

3 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3066
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DSPIC33EP128GM306 2019/08/20 07:04:23 (permalink)
    0
    Suggestions?
    1. Check the clock output
    2. Check the SDO signal
    A scope is a wunderful device, a logic analyzer should do as well.
     
    I suppose, we'll hear (read) from you again.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    rodims
    Super Member
    • Total Posts : 1519
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: offline
    Re: DSPIC33EP128GM306 2019/08/20 07:54:24 (permalink)
    0
    You wrote you already checked the "correct writing with SPI".
    You should explainhow you exactly do that,- so as du000001 writes, at least you need to check both the clock and SDO pins when writing some byte like e.g. 0x33.
    I see in the manual that SPI1 is not remappable, so no problems with PPS.
     
    If your SDO and SCK is OK, and SDO is connected to SDI, then you possibly should show your SPI1_Exchange8bit function.
    The purpose of OUT_11_ON  is not clear, because you call it in the loop without setting anything OFF.

    If something like this happens, and I think I have done everything correct, then I hard-wire SDI to Vcc.  Your input should now be 0xff.
    If not, check your wiring, I usually do this by just using SDI1 as a normal input pin (RA4 in your case, do not enable SPI).  Does the input follow if you apply GND or Vcc to RA4 ? 
    If that works, then you can go back and check each and every setting of your SPI initialization code.
    I did not take the time to verify comments against cryptic value.
    It's usually better to use the definitions from the include file as you did it e.g. for
    SPI1CON1bits.CKE

     
    #3
    ric
    Super Member
    • Total Posts : 23860
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DSPIC33EP128GM306 2019/08/20 13:34:28 (permalink)
    0
    You did not show any of your pin initialisation code.
    Did you switch your SDI pin from analog to digital mode?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5