electronics- mcp 3008 communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · mcp...
TRANSCRIPT
![Page 1: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/1.jpg)
MCP Communication
ElectronicsMCP 3008 Communication
Terry Sturtevant
Wilfrid Laurier University
January 30, 2019
Terry Sturtevant Electronics MCP 3008 Communication
![Page 2: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/2.jpg)
MCP Communication
MCP Communication
The Python examples of code to communicate with theMCP3008 can be confusing.Looking at the code and the appropriate timing diagram helps.
Terry Sturtevant Electronics MCP 3008 Communication
![Page 3: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/3.jpg)
MCP Communication
MCP Communication
The Python examples of code to communicate with theMCP3008 can be confusing.
Looking at the code and the appropriate timing diagram helps.
Terry Sturtevant Electronics MCP 3008 Communication
![Page 4: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/4.jpg)
MCP Communication
MCP Communication
The Python examples of code to communicate with theMCP3008 can be confusing.Looking at the code and the appropriate timing diagram helps.
Terry Sturtevant Electronics MCP 3008 Communication
![Page 5: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/5.jpg)
MCP Communication
adc=s p i . x f e r 2 ( [ 1 , ( 8+ a d c c h a n n e l )<<4 ,0])
This transfers 3 bytes; the first is simply ’1’, and the last is simply’0’
Terry Sturtevant Electronics MCP 3008 Communication
![Page 6: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/6.jpg)
MCP Communication
adc=s p i . x f e r 2 ( [ 1 , ( 8+ a d c c h a n n e l )<<4 ,0])
This transfers 3 bytes;
the first is simply ’1’, and the last is simply’0’
Terry Sturtevant Electronics MCP 3008 Communication
![Page 7: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/7.jpg)
MCP Communication
adc=s p i . x f e r 2 ( [ 1 , ( 8+ a d c c h a n n e l )<<4 ,0])
This transfers 3 bytes; the first is simply ’1’, and the last is simply’0’
Terry Sturtevant Electronics MCP 3008 Communication
![Page 8: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/8.jpg)
MCP Communication
(8+ a d c c h a n n e l )<<4
The channel is a 3 bit value, so adding 8 gives a single hex digit;this value then is shifted 4 bits to the left
Terry Sturtevant Electronics MCP 3008 Communication
![Page 9: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/9.jpg)
MCP Communication
(8+ a d c c h a n n e l )<<4
The channel is a 3 bit value, so adding 8 gives a single hex digit;
this value then is shifted 4 bits to the left
Terry Sturtevant Electronics MCP 3008 Communication
![Page 10: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/10.jpg)
MCP Communication
(8+ a d c c h a n n e l )<<4
The channel is a 3 bit value, so adding 8 gives a single hex digit;this value then is shifted 4 bits to the left
Terry Sturtevant Electronics MCP 3008 Communication
![Page 11: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/11.jpg)
MCP Communication
adc=s p i . x f e r 2 ( [ 1 , ( 8+ a d c c h a n n e l )<<4 ,0])
First byte (first non-zero bit is start)
Terry Sturtevant Electronics MCP 3008 Communication
![Page 12: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/12.jpg)
MCP Communication
adc=s p i . x f e r 2 ( [ 1 , ( 8+ a d c c h a n n e l )<<4 ,0])
Second byte (1st bit indicates single or double; next 3 indicate chan-nel)
Terry Sturtevant Electronics MCP 3008 Communication
![Page 13: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/13.jpg)
MCP Communication
adc=s p i . x f e r 2 ( [ 1 , ( 8+ a d c c h a n n e l )<<4 ,0])
Third byte (don’t care)
Terry Sturtevant Electronics MCP 3008 Communication
![Page 14: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/14.jpg)
MCP Communication
data =(( adc [1]&3)<<8) +adc [ 2 ]
The response is also a 3 byte transfer; the first byte will be ’0’, andthe last two contain data
Terry Sturtevant Electronics MCP 3008 Communication
![Page 15: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/15.jpg)
MCP Communication
data =(( adc [1]&3)<<8) +adc [ 2 ]
The response is also a 3 byte transfer;
the first byte will be ’0’, andthe last two contain data
Terry Sturtevant Electronics MCP 3008 Communication
![Page 16: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/16.jpg)
MCP Communication
data =(( adc [1]&3)<<8) +adc [ 2 ]
The response is also a 3 byte transfer; the first byte will be ’0’, andthe last two contain data
Terry Sturtevant Electronics MCP 3008 Communication
![Page 17: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/17.jpg)
MCP Communication
( adc [1]&3)<<8
Anding with 3 gets the bottom two bits of the second byte; it isthen shifted left 8 bits so it will be bits 8 and 9
Terry Sturtevant Electronics MCP 3008 Communication
![Page 18: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/18.jpg)
MCP Communication
( adc [1]&3)<<8
Anding with 3 gets the bottom two bits of the second byte;
it isthen shifted left 8 bits so it will be bits 8 and 9
Terry Sturtevant Electronics MCP 3008 Communication
![Page 19: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/19.jpg)
MCP Communication
( adc [1]&3)<<8
Anding with 3 gets the bottom two bits of the second byte; it isthen shifted left 8 bits so it will be bits 8 and 9
Terry Sturtevant Electronics MCP 3008 Communication
![Page 20: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/20.jpg)
MCP Communication
data =(( adc [1]&3)<<8) +adc [ 2 ]
First byte (adc[0]) (discard)
Terry Sturtevant Electronics MCP 3008 Communication
![Page 21: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/21.jpg)
MCP Communication
data =(( adc [1]&3)<<8) +adc [ 2 ]
Second byte (adc[1]) (last two bits matter)
Terry Sturtevant Electronics MCP 3008 Communication
![Page 22: Electronics- MCP 3008 Communicationdenethor.wlu.ca/pc320/lectures/mcp3008beam.pdf · MCP Communication (8+adc channel)](https://reader034.vdocuments.mx/reader034/viewer/2022042713/5fb22ccd9617152b474cdde3/html5/thumbnails/22.jpg)
MCP Communication
data =(( adc [1]&3)<<8) +adc [ 2 ]
Third byte (adc[2]) (bottom 8 bits of 10 bit value)
Terry Sturtevant Electronics MCP 3008 Communication