• AVR Freaks

Hot!What happen when slave is ADC device ?

Author
madakegajya
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/12/06 02:19:30
  • Location: 0
  • Status: offline
2020/02/25 05:36:18 (permalink)
0

What happen when slave is ADC device ?

I am trying to understand the basic concepts of SPI communication. SPI always sends one byte and receives one byte at a time.  The master holds the byte that was in the shift register of the slave and the slave holds the byte that was in the shift register of the master.  For example :-
 
If microcontroller send byte = 0x10 , slave will receive byte = 0x10 after 8 clock pulses 
 
What happen when slave is ADC device ?
 
I have read that micro sends dummy bytes to read slave if microcontroller send dummy byte = 0x10 to ADC slave , What the data slave will hold at this time ?
 
Note : I am just trying to understand basics that's why I didn't mention specific  microcontroller and ADC
#1

8 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1631
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: What happen when slave is ADC device ? 2020/02/25 06:18:33 (permalink)
    +2 (2)
    madakegajya
     
    What happen when slave is ADC device ?
     
    I have read that micro sends dummy bytes to read slave if microcontroller send dummy byte = 0x10 to ADC slave , What the data slave will hold at this time ?

    It doesn't matter if the slave is an ADC device, With SPI data is always exchanged.
    If you send dummy data from master to slave, I assume you want to read data from slave, then the slave will just exchange by sending the required data, in this case the ADC value.
    So if you're just reading data from the other device and it's not important what data you send, it's common to to either send the "don't care" bytes 0x00 or 0FF.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 18388
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: What happen when slave is ADC device ? 2020/02/25 08:53:33 (permalink)
    +3 (3)
    An ADC works like ever other SPI device.
    There is not ADC basics.  The Chip works per its data sheet.  There is no standard.  different chips use different methods.
    #3
    madakegajya
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/12/06 02:19:30
    • Location: 0
    • Status: offline
    Re: What happen when slave is ADC device ? 2020/02/25 08:54:16 (permalink)
    0
    katela
     
    It doesn't matter if the slave is an ADC device, With SPI data is always exchanged.
    If you send dummy data from master to slave, I assume you want to read data from slave, then the slave will just exchange by sending the required data, in this case the ADC value.

    Let's say the five ADC values ​​of the sensor are as follows
     
    ADC = 0x01
    ADC = 0x02
    ADC = 0x03
    ADC = 0x04
    ADC = 0x05
     
    Dummy byte = 0x00

    MCU - 8 clock - Slave 
    0x00 - 8 pulses - 0x01  /* MCU send dummy byte */
    0x01 - 8 pulses - 0x01 /* MCU read ADC value 0x01 */
    0x02 - 8 pulses  - 0x02  /* MCU read ADC value 0x02 */
    0x03 - 8 pulses -  0x03  /* MCU read ADC value 0x03 */
    0x04 - 8 pulses - 0x04   /* MCU read ADC value 0x04 */
    0x05 - 8 pulses - 0x05 /* MCU read ADC value 0x05 */
    ...............................
    byte  - 8 pulses - byte /* MCU read ADC value byte  */

     
    #4
    LdB_ECM
    Super Member
    • Total Posts : 297
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: What happen when slave is ADC device ? 2020/02/25 09:10:04 (permalink)
    +2 (2)
    No if you want 5 byte back from the ADC you have to pump out 5 dummy bytes from master :-)
    The incoming register does not automatically go to the output ... it is a MASTER not a slave it breaks the chain so yoiu pump 5 dummy bytes.
     
    The reality is usually an SPI device with 5 registers like that would need an address sent out.
     
    There is no standard but lets setup the most complex the device needs a command (such as read/write/config) then an address then the byte (read or write)
     
    So the sequence from the master for such a device to read would send 3 bytes
    1.) Read Command Identifier
    2.) Address of register to be read
    3.) Send a dummy byte 0x00 0xFF
     
    So the ADC would send back 3 bytes .. 2 of which will be dummies
    1.) Dummy byte for read command identifier
    2.) Dummy byte for command
    3.) Actual 8 bit ADC channel value
     
    The important thing to realize is it a simple shift register setup as the master clocks out so must the slave. So the master must pump as many bytes as it requires to read.
     
    To get into any greater detail you actually need to select an ADC.
     
     
    post edited by LdB_ECM - 2020/02/25 09:22:53
    #5
    pcbbc
    Super Member
    • Total Posts : 1631
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: What happen when slave is ADC device ? 2020/02/25 09:22:22 (permalink)
    +2 (2)
    5 consecutive ADC conversions from the same single channel?  Or does this notional ADC device only have more than one channel?
     
    If only a single channel device, then it may well work as you describe.  Otherwise there may be some way to set a control register first to decide which channel you are reading.  Then possibly successive "dummy bytes" may bead successive incrementing channels, or the same channel.
     
    Depends how the device is designed.  Really any number of embodiments are possible...
     
    But yes, if you have more than one byte to read over SPI, and no data the send, just keep sending multiple dummy bytes.  Every time you send one to a slave that supports send multiple bytes, it will cause it to clock out another response.
     
    Usually the data you send for the "dummy" byte isn't important, so you can send increasing bytes if you want: 0x00,0x01,0x02,0x03,0x04...
    However conventionally you'd usually use send the same fixed dummy value, usually 0x00 or 0xFF, each time.
    #6
    1and0
    Access is Denied
    • Total Posts : 10546
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: What happen when slave is ADC device ? 2020/02/25 10:13:51 (permalink)
    +1 (1)
    It is called a dummy byte because the slave will ignore it; so the value of the dummy byte is irrelevant. It is the action of the master transmitting (clocking out) the byte that matter; i.e. it clocks the data bytes to/from the slave. As said, a SPI communication is an exchange of two data bytes.
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 18388
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: What happen when slave is ADC device ? 2020/02/25 10:36:48 (permalink)
    +1 (1)
    there are no generalities here. do you have a specific chip in mind?
     
    Example 1: fictional (12 bit multi channel A/D):
    byte 1 send address, receive dummy.
    byte 2 to send dummy, receive High byte.
    byte 3 to send dummy, receive low byte.
     
    Example 2: fictional (16 bit one channel A/D) :
    byte 1 to send dummy, receive High byte.
    byte 2 to send dummy, receive low byte.
     
    Example 2: fictional (8 bit multi channel A/D) :
    byte 1 send address 1, receive garbage byte.
    byte 2 send address 2, receive value 1.
    byte 3 send address 3, receive value 2.
     
    #8
    ric
    Super Member
    • Total Posts : 26058
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: What happen when slave is ADC device ? 2020/02/25 12:15:37 (permalink)
    +2 (2)
    madakegajya
    Note : I am just trying to understand basics that's why I didn't mention specific  microcontroller and ADC

    This is where you made your mistake.
    There are no basics, it totally depends upon what the datasheet for the ADC you want to use says.
    i.e. you have to read the ADC datasheet, and do what IT tells you to do, which may include selecting channels, starting a conversion, waiting for a conversion to complete.
    There is NO STANDARD procedure.
     
     

    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!
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5