• AVR Freaks

Hot!PIC24F16 I2C interface Slave mode -- How can I detect the end of transmission

Page: 12 > Showing page 1 of 2
Author
user2x
Super Member
  • Total Posts : 239
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
2019/08/21 22:36:49 (permalink)
0

PIC24F16 I2C interface Slave mode -- How can I detect the end of transmission

I am working on a I2C slave implementation that uses variable length master write packets.
 
 
There seems no facility to get an interrupt on the bus stop condition on this PIC chip type.
 
Since this is usually the method I use to determine that a transmission has finished and to start parsing it, I am now stumped.
 
How is one supposed to determine when a complete packet from the master has been recieved? 
 
A timeout perhaps but since there is no minimum clock speed defined by I2C, it is possible that a packet can take a very long time.
 
How have others done this on this chip type?
 
Regards
X
 
 
 
post edited by user2x - 2019/08/22 01:45:26
#1

25 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23535
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/21 22:44:10 (permalink)
    0
    There is no such device as "PIC14F16". What is the full part name?
     

    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!
    #2
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 01:48:15 (permalink)
    0
    Yea ok so I fixed the typo in the title
    PIC24F16
     
    And the  user manual section  is common  for the whole family.
    #3
    ric
    Super Member
    • Total Posts : 23535
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 01:57:28 (permalink)
    5 (1)
    That is not a complete part number. Please stop wasting time and specify an exact part, then I can check the datasheet for THAT PART.
     

    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
    ric
    Super Member
    • Total Posts : 23535
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 02:08:48 (permalink)
    0
    As an example, the first "PIC24F16..." datasheet I looked in is for the PIC24F16KL402 FAMILY.
    Those devices most certainly CAN generate an interrupt on the STOP condition.
    What part are you using that cannot?
     

    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!
    #5
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 02:10:45 (permalink)
    0
    It could be PIC24F16KA102.
    But you will waste your time looking at the datasheet since it has no details.
    You will, also waste your time looking at the product link for that chip on microchip.com as it is missing the link to the I2C section, unless they added it since yesterday.
     
    post edited by user2x - 2019/08/22 02:22:30
    #6
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 02:17:40 (permalink)
    0
    ric
    As an example, the first "PIC24F16..." datasheet I looked in is for the PIC24F16KL402 FAMILY.
    Those devices most certainly CAN generate an interrupt on the STOP condition.
    What part are you using that cannot?
     


    ric
     
    I seem to remember it is PIC24F16KA102. I am not in the office so cannot verify 100% but
    look, the reference  manual is common to the whole  PIC24 series and PIC33. So you would see the same info for all these chips.
     
    I would be surprised if it can generate the S interrupt. In master mode perhaps but in slave mode -I think not.
     
    Please tell me more.
     




    post edited by user2x - 2019/08/22 02:21:29
    #7
    ric
    Super Member
    • Total Posts : 23535
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 02:24:10 (permalink)
    0
    user2x
    It could be PIC24F16K102.

    No such device.
    Do you mean PIC24F16KA102
     

    But you will waste your time looking at the datasheet since it has no details.[/quoute]
     
    You will, also waste your time looking at the product link for that chip on microchip.com as it is missing the link to the I2C section, unless they added it since yesterday.

    If it is a PIC24F16KA102,, then you're right, the link is faulty. It is trying to go to
    http://ww1.microchip.com/...eviceDoc/70000195g.pdf
    an educated guess reveals the previous revision is available.
    http://ww1.microchip.com/...eviceDoc/70000195f.pdf
     
    I agree, these devices don't seem to have a STOP interrupt.
    A workaround would be to poll the P bit in a timer interrupt.

    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!
    #8
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 02:32:11 (permalink)
    0
    Yes, exactly.
     
    I am not sure how I would poll the stop condition bit in a timer interrupt.
    I would have billions of interrupts clogging an already busy system.
     
    Ok, I know that I will have to somehow compromise to make this work but how do you invisige that?
     
    I shake my head at the designers of this chip family.
     
     
    #9
    ric
    Super Member
    • Total Posts : 23535
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 02:50:42 (permalink)
    0
    user2x
    Yes, exactly.
     
    I am not sure how I would poll the stop condition bit in a timer interrupt.

    Do you have a regular timer interrupt already?
    In nearly every system I design, I have a timer running every 1ms or 10ms.
    It makes all sorts of timing and housekeeping much easier.
     
    I don't see the difficulty. If you check the P bit in a 1ms interrupt, at most it will be 1ms after the transmission ends until you detect it.

    I would have billions of interrupts clogging an already busy system.

    I don't follow this.
     

    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!
    #10
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 03:01:07 (permalink)
    0
    Yes of courxe, I could do it in the 1ms systick I have. But that is way slow and inefficient.
    I am also not sure if that bit only sets for transmissions started with the matching i2c  chip address.
     
    But you are right, I will have to spend extra time to work around this ridiculous problem.
     
    Another reason for moving the new designs to ST...
     
     
     
    #11
    ric
    Super Member
    • Total Posts : 23535
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 03:18:49 (permalink)
    5 (1)
    user2x
    Yes of courxe, I could do it in the 1ms systick I have. But that is way slow and inefficient.

    Why? It's only a couple of instructions.
    You only need to do it from the point where you detect an address match, until the first detection of P true.
     

    I am also not sure if that bit only sets for transmissions started with the matching i2c  chip address.

    The start and stop status bits are always active. That is the whole point, so you can use them to track the current status of the bus.
     
     

    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!
    #12
    NKurzman
    A Guy on the Net
    • Total Posts : 17708
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 05:39:50 (permalink)
    0
    You could move to ST or you can choose a PIC that suits your needs there are other PIC24 chips that do have the stop interrupt.
    In fact you may be able to find one that is drop in compatible to yours.
    #13
    Jerry Messina
    Super Member
    • Total Posts : 417
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 06:04:48 (permalink)
    0
    I think you have to watch polling the S and P bits since they reflect the current state of the bus.
     
    If the master begins another transaction shortly after sending a STOP (P), the START (S) bit will be set again and you may miss the P event.
     
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3233
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 06:53:33 (permalink)
    0
    What do you mean by packet, some structure that has header and data?
     
    "How have others done this on this chip type?"
    What i2c device?

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #15
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 14:16:20 (permalink)
    0
    Jerry Messina
    I think you have to watch polling the S and P bits since they reflect the current state of the bus.
     
    If the master begins another transaction shortly after sending a STOP (P), the START (S) bit will be set again and you may miss the P event.
     


    This is a multi slave bus so there are other start stop conditions happening quite quickly.
     
    I am thinking that I will have to start the polling mechanism at the address match interrupt and end it when the P condition has polled. 
     
    A bit of a schlepp really as I now have to operate I2C not just from the I2C code but also through a timer.
    The parsing start of the packet now has to be done based on some flag that is being set in the timer routine once it find the P condition as true.
     
    X
     
     
    #16
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 19:35:05 (permalink)
    0
    NKurzman
    You could move to ST or you can choose a PIC that suits your needs there are other PIC24 chips that do have the stop interrupt.
    In fact you may be able to find one that is drop in compatible to yours.

     
    Are you sure about that?
     
    So far there is only one reference manual named "dsPIC33/PIC24 Family reference Manual".
    I states that it supersedes:

    dsPIC33F/PIC24H Family Reference Manual
    DS70330 19 dsPIC33E/PIC24E Family Reference Manual
    DS39702 24 PIC24F Family Reference Manual
    DS70235 19 PIC24H Family Reference Manual
    DS70068 21 dsPIC30F Family Reference Manual

     
    That manual has ONLY the type of I2C interface in it that I am dealing with.
    So what others PIC24 chips are you referring to?
     
    X
     
     
    #17
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/22 19:39:11 (permalink)
    0
    Jerry Messina
    If the master begins another transaction shortly after sending a STOP (P), the START (S) bit will be set again and you may miss the P event.

     
    I think that could be right. Tricky.
    I can't think of any other options though.
    Unless we re-write the higher level comms protocol to have fixed length tranmissions for master write.
    Not nice!
     
    X
    #18
    Jerry Messina
    Super Member
    • Total Posts : 417
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/08/23 03:20:31 (permalink)
    0
    If you have variable length packets, how about including a 'length' byte as part of the packet structure?
     
    #19
    user2x
    Super Member
    • Total Posts : 239
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC14F16 I2C interface Slave mode -- How can I detect the end of transmission 2019/09/05 16:47:08 (permalink)
    0
    This is proving to be a real issue.
     
    I used polling as described for the P bit from a timer. That works only if there is enough gap between packets.
    Turns out that sometimes there is not (<20us) and I miss the P.
     
    So I upped the speed of the polling timer to 5us resolution to catch this elusive P.
    Now, there is no time to run the main loop or much else.
     
    I am wondering how they intended to use this bus if there is no way to get an irq on P.
     
    I am out of ideas at the moment.
     
    Regards
    X
     
     
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5