You are on page 1of 16

Sync Serial

ECET 209 – Introduction to


Microcontrollers
Overview

• Review Homework #8
• Study Timing Diagram for MAX1243
• Develop an Algorithm to Interface with the
MAX1243
Homework #8
MAX1243 10-Bit ADC
Algorithm for MAX1243
• Take the Chip Select Line Low
• Wait for EOC
• Take the CLK High
• Take CLK back Low
• Take the CLK High
• Read the Data bit
• Take the CLK Low
• …
• Bring the Chip Select Line High
Reading Serial Data

7 6 5 4 3 2 1 0
Reading Serial Data
• When Reading Serial Data, it is very
common to use a “shifting” operation
– Get the 1st bit of data
– Shift the data (inside a variable)
– Get the 2nd bit of data
– Shift the data
– …
Reading Serial Data (MSB 1st)

7
7 6
7 6 5
7 6 5 4

7 6 5 4 3 2 1 0
Reading Serial Data (LSB 1st)

0
1 0
2 1 0
3 2 1 0

7 6 5 4 3 2 1 0
Reading Serial Data

• Word of Caution ( software guideline )


– Do not shift the data until you are ready to read
the next bit
• Only shift the data before reading the next bit
• Not after reading
– Shifting data after reading the bit may result in
shifting a data bit out of the variable boundaries
Reading Serial Data

• Use an IF construct to test the incoming


serial bit of data
if ( DOUT != 0 )
{

}
• If the bit of data is “set” use a Bitwise OR
to set the corresponding bit in the variable
Reading Serial Data (MSB 1st)

• Use an IF construct to test the incoming


serial bit of data
if ( DOUT != 0 )
{
value = value | 0x01;
}
• If the bit of data is “set” use a Bitwise OR
to set the corresponding bit in the variable
Reading Serial Data (LSB 1st)

• Use an IF construct to test the incoming


serial bit of data
if ( DOUT != 0 )
{
value = value | 0x80;
}
• If the bit of data is “set” use a Bitwise OR
to set the corresponding bit in the variable
Reading Serial Data

• Use a For Loop ( I start with n # of bits and


count down)
– Shift the variable to make room for the new
data bit that is going to be read
– Read the data bit
– Work the Clock
MAX1243 10-Bit ADC

You might also like