• AVR Freaks

Hot!Pic32 Spi problem...

Author
Nome BuTT
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2015/09/19 04:19:09
  • Location: Karachi,Pakistan
  • Status: offline
2019/04/10 05:33:24 (permalink)
0

Pic32 Spi problem...

Hello
 
I m using pic32mx230 series on Harmony Design. In Spi 8 bit mode when I send like this 
static uint8_t *c;
static uint8_t d[4];
c = d;
// DAC4_DGAIN
d[0]=0x00; d[1]=32; d[2]=0x00; d[3]=40;
Reg_updates_DAC(c);
 
getting results perfect as We need on Logic analyzer   0x00 0x32 0x00 0x40 
 
But When I send Like this 
static uint16_t *c;
static uint16_t d[2];
c = d;
// DAC4_DGAIN
d[0]=0x0032; d[1]=0x0040;
Reg_updates_DAaC(c);
why we getting Data like 0x32  0x00    0x40  0x00 on Logic analyzer
 
How can I get results like this 0x0032 0x0040 ?
Thanks
Nome
post edited by Nome BuTT - 2019/04/10 05:37:12
#1

10 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17248
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Pic32 Spi problem... 2019/04/10 06:01:26 (permalink)
    0
    Google Big Endian.
    If you need the bytes the other way stick with 8-bit or swap bytes in the 16 bit words.
    #2
    Nome BuTT
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2015/09/19 04:19:09
    • Location: Karachi,Pakistan
    • Status: offline
    Re: Pic32 Spi problem... 2019/04/10 08:00:09 (permalink)
    0
    Hello
    Thanks for your Reply 
    sir how to change Little Endian to Big endian in pic32mx harmony design ?
    one more Thing I want to ask !
    if my Data is like 0x1234 16bit case and if I  change my SPI Width 8 bit to 16 bit what will happend ?again Swap bytes issue will occurred ?must be change Little Endian to Big endian    
     
    Kindly help us 
     
    Thanks 
     Nome
    post edited by Nome BuTT - 2019/04/10 09:55:35
    #3
    qhb
    Superb Member
    • Total Posts : 9992
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Pic32 Spi problem... 2019/04/10 14:00:02 (permalink)
    5 (1)
    nome
    sir how to change Little Endian to Big endian in pic32mx harmony design ?

    You can't. The PIC32 is a little endian chip.
    NKurzman already said what you have to do.
     

    Only 10 to go...
    #4
    qhb
    Superb Member
    • Total Posts : 9992
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Pic32 Spi problem... 2019/04/11 04:34:25 (permalink)
    0
    I saw the reply posted then deleted by Nome.
    I guess they actually took the time to read the reference they were linking to, which confirms the PIC32 is little endian only.
     

    Only 10 to go...
    #5
    Nome BuTT
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2015/09/19 04:19:09
    • Location: Karachi,Pakistan
    • Status: offline
    Re: Pic32 Spi problem... 2019/04/11 05:15:56 (permalink)
    0
    qhb
    I saw the reply posted then deleted by Nome.
    I guess they actually took the time to read the reference they were linking to, which confirms the PIC32 is little endian only.
     


    grin: grin
    yes you are right Sir  but what will  the solution how to swap bytes ?
    #6
    qhb
    Superb Member
    • Total Posts : 9992
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Pic32 Spi problem... 2019/04/11 05:22:26 (permalink)
    0
    There's no magic way.
    Just make a function to swap the upper and lower byte of a 16 bit value, and use it.
     
     

    Only 10 to go...
    #7
    Nome BuTT
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2015/09/19 04:19:09
    • Location: Karachi,Pakistan
    • Status: offline
    Re: Pic32 Spi problem... 2019/04/11 05:59:38 (permalink)
    0
    Thanks for reply
    One last thing i want to ask Sir I have two Dac with same SPI line different CS First Dac are supporting 8 bit width and second dac are supporting 16bit width  how to change width during running program ?
    1.when I send 8 bit data first we have to assign ?  
    #define DRV_SPI_COMM_WIDTH_IDX0      SPI_COMMUNICATION_WIDTH_8BITS
    2.when I send 16 bit data first we have to assign?  
    #define DRV_SPI_COMM_WIDTH_IDX0      SPI_COMMUNICATION_WIDTH_16BITS
     
    what will easy way ?
     
    Thanks 
    Nome
     
    #8
    NKurzman
    A Guy on the Net
    • Total Posts : 17248
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Pic32 Spi problem... 2019/04/11 08:43:43 (permalink)
    0
    You need to disable the SPI before changing modes, then re-enable it.
     
    For SPI you can handle a 16 bit transfer as two 8 bit transfers.  The DAC will not care.  This will also solve your Endian Problem.
    #9
    Nome BuTT
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2015/09/19 04:19:09
    • Location: Karachi,Pakistan
    • Status: offline
    Re: Pic32 Spi problem... 2019/04/11 10:52:51 (permalink)
    0
    Thanks Bro for your informative Reply 
     
    Sir
     
           I m already using two 8 bit spi client one of Dac Results are good as we need.
    But second one We are sending 350 multi tones pattern to pic32mx. Shapes of Tones is perfect as i need on Spectrum Analyzer but number of Multi-tones we are getting below of 100 it mean we are not getting hole Bandwidth.
    Actually we have RF signal generator they use pic32mx  series I read and save spi pattern from our logic Analyzer 350 numbers of Multi-Tones  I resend to our Pic32mx 
    every thing is perfect as i seen on logic analyzer read pattern and Write pattren but Issue is number of tones 
    I did read carefully again DAC pdf I realize its all Address and data is 16 bit
    I asked Analog Devices they said that you should  use 16 bit spi width
    Thatswhy I feel to change my design 8bit to 16bit   
     
    Thanks
    Nome    
    #10
    Nome BuTT
    Starting Member
    • Total Posts : 37
    • Reward points : 0
    • Joined: 2015/09/19 04:19:09
    • Location: Karachi,Pakistan
    • Status: offline
    Re: Pic32 Spi problem... 2019/04/16 00:04:17 (permalink)
    0
    Hi
        I attached both 8 bit and 16 bit Pictures and my question is when our DAC need 16 bit data and also 16 bit addresses 
    can I use 8bit.png ?
    In 8bit.png case I don t have swap byte Issue 
    Thanks
    Nome
    post edited by Nome BuTT - 2019/04/16 00:09:11

    Attached Image(s)

    #11
    Jump to:
    © 2019 APG vNext Commercial Version 4.5