• AVR Freaks

Hot!PIC18F45K80 to QT1481 sensor SPI

Page: 12 > Showing page 1 of 2
Author
mateusz24052
Starting Member
  • Total Posts : 75
  • Reward points : 0
  • Joined: 2018/10/18 02:21:41
  • Location: 0
  • Status: offline
2018/11/19 06:53:57 (permalink)
0

PIC18F45K80 to QT1481 sensor SPI

I cannot seem to post new thread.
 
Topic: SPI for PIC18F45K80 to QT1481 sensor
 
PIC18F45K80 to QT1481 sensor
 
Does the setup look correct?
 
What do I need to add to make SS low when data is transmitted?
 
If I send 0x0F to SDO, I should get back 0xF0 from SDI from PIC.
 
Green being MOSI,
Yellow being MISO,
Pink being SS_B
 
 ////////////// Update
 
This my updated code and I am getting closer but I don't know why my SS is not working. SS must be low to transmit a byte (command)
post edited by mateusz24052 - 2018/11/20 02:42:34

Attached Image(s)

#1

39 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/19 15:30:02 (permalink)
    +1 (1)
    SS is manually controlled by YOUR CODE in the Master, the peripheral doesn't do it.
    So, you must drive the GPIO pin low, do the transfers via the peripheral, wait for the last one to complete, then raise the SS pin again.
     

    Nearly there...
    #2
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 01:05:58 (permalink)
    0
    How do you do that? Is it to do with LATs?
    #3
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 01:09:33 (permalink)
    +1 (1)
    mateusz24052
    How do you do that? Is it to do with LATs?

    Yes, you just switch the pin low and high the same as any other GPIO pin.

    Nearly there...
    #4
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 01:12:12 (permalink)
    0
    So if my SS is at RE2, would it looks something like this:


    void main(void)
    {
    SYSTEM_Initialize() ;

    while (1)
    {
    LATEbits.LATE2 = 0 ; // Transmit data
    char temp;
    WriteSPI(0x0F); // Send a byte
    while(!DataRdySPI()); // wait for a data to arrive
    temp = ReadSPI(); // Read a byte from the
    LATEbits.LATE2 = 1 ;
    }
    }
    #5
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 01:16:20 (permalink)
    0
    I cannot see that SS is high when idle and low when transfering data
     
    #6
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 01:25:16 (permalink)
    +1 (1)
    The call to DataRdySPI() is not doing anything useful, the WriteSPI() and ReadSPI() functions you are using do not return until that transfer is complete.

    Did you write to TRIES to make RE2 an output pin?
     
    What exactly do you mean by "I cannot see that SS is high when idle and low when transfering data"
    How exactly are you testing that?
     

    Nearly there...
    #7
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 01:37:55 (permalink)
    0
    So I removed the DataRdySPI() and nothing changed.
     
    When I am only expecting data to be sent if SS is low and from the picture you can see that SS doesn't do anything. Did I do something wrong?
     
    I attached a photo of what I see
    #8
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 01:43:56 (permalink)
    0
    Clock idle: High
    Clock shift out edge: Falling
    Clock data edge: Rising

    Does this look correct on the photo?
    #9
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 02:13:04 (permalink)
    +1 (1)
    Please don't go changing the first post once you start getting answers.
    Otherwise it gets very confusing what is old and what is new.
    There's no labels on your screens. Which trace is SS?
     
    I already asked once if you made the RE2 pin an output. The code in post#1 writes 0x07 to TRISE, which makes that pin an input.

    Nearly there...
    #10
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 02:18:41 (permalink)
    0
    I'm sorry, I will not do that again.
     
    The trace SS is the pink line.
     
    I have set QTB_SS_TRIS = 0 and the TRISE as 0x00 so all are output.
     
    Nothing has changed. SS not changing state.
     
    It also seems that not all MOSI is 0x0F with the clock blue line.
    #11
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 02:24:58 (permalink)
    +1 (1)
    Could you post your entire C file?
    Neither of the files attached to your first post agree with what you say is in your code.
     

    Nearly there...
    #12
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 02:31:12 (permalink)
    0
    I am trying to copy and paste my code but nothing happens when I press submit post
    #13
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 02:39:00 (permalink)
    +1 (1)
    Attach the file like you did in the first post.
    There's probably something in your code triggering the forum firewall. The most common is to have "char" followed by "(" without at least two spaces between them.
     

    Nearly there...
    #14
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 02:43:07 (permalink)
    #15
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 02:56:32 (permalink)
    +1 (1)
    Why have you edited the first post again?

    Nearly there...
    #16
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 02:59:08 (permalink)
    0
    Here's the code. I didn't realise you could attach files on a new post
    #17
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 03:00:52 (permalink)
    +1 (1)
    It's your function called "out_char" that is triggering the firewall.
    There's nothing wrong with that as a name, it's just the stupid firewall running on the web server for this forum that thinks it is a bad expression.
     
    Here's your problem
    #define QTB_SS_LAT_LOW LATEbits.LATE2 = 0 ;
    #define QTB_SS_LAT_HIGH LATEbits.LATE2 = 0 ;



    The second line should "=1", not "=0"
    That's one reason why I think obscuring your code with macros like this is a BAD idea.
     
     

    Nearly there...
    #18
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 03:04:16 (permalink)
    0
    Oh I see. It was driving me nuts with the out_char. Are there any other things I shoudl worry about?
     
    I will do the changes and get back to you
    #19
    mateusz24052
    Starting Member
    • Total Posts : 75
    • Reward points : 0
    • Joined: 2018/10/18 02:21:41
    • Location: 0
    • Status: offline
    Re: PIC18F45K80 to QT1481 sensor SPI 2018/11/20 03:11:12 (permalink)
    0
    The SS works now. But I am very confused now. Why is it that I am getting two clocks in between SS lows? I can see in MOSI that I send 0x0F but not sure what the next thing is. What I am trying to do is send 0x0F and receive 0xF0 in MISO? I cannot see it unless I am blind.
     

    Attached Image(s)

    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5