EE 308 Spring 2011 • Using the MC9S12 IIC Bus with DS 1307 Real Time Clock • DS1307 Data Sheet • The MC9S12 Serial Communication Interface (SCI) • MC9S12 SCI Block Guide V02.05 • Huang, Sections 9.2-9.6 Dallas Semiconductor DS1307 Real Time Clock • The DS 1307 is a real-time clock with 56 bytes of NV (non-volatile) RAM • It uses the IIC bus, with address 11010002 • It stores date and time – Data are stored in BCD format • It uses a 32.768 kHz crystal to keep time • It can generate a square wave output – Frequency of square wave can be 1 Hz, 4.096 kHz, 8.192 kHz or 32.768 kHz • It uses a battery to hold the date and time when your board is not poweredEE 308 Spring 2011 Using the Dallas Semiconductor DS1307 Real Time Clock • Set up the IIC bus – Find the SCL frequency, SDA hold time, Start and Stop hold times – Determine the value to write to IBFD to meet those times • To set the time, – Send the Start condition – Write address of clock (with R/Ŵ low) – Write a 0 (to select seconds register), – Write second, minute, hour, day of week, day of month, month, year, control • Control determines whether or not to enable square wave, and selects frequency – Send the Stop condition • To read the clock, – Send the Start condition – Write the address of the clock (with R/Ŵ low), then write a 0 (to select seconds register). – Send the Stop condition – Send the Start condition – Write the address of the clock (with R/Ŵ high) – Read the time registers. – Send the Stop condition • If you want to store some data which will remain between power cycles, you can write it to the 56 bytes of NV RAMEE 308 Spring 2011 Asynchronous Data Transfer • In asynchronous data transfer, there is no clock line between the two devices • Both devices use internal clocks with the same frequency • Both devices agree on how many data bits are in one data transfer (usually 8, sometimes 9) • A device sends data over an TxD line, and receives data over an RxD line – The transmitting device transmits a special bit (the start bit) to indicate the start of a transfer – The transmitting device sends the requisite number of data bits – The transmitting device ends the data transfer with a special bit (the stop bit) • The start bit and the stop bit are used to synchronize the data transferEE 308 Spring 2011 Asynchronous Data Transfer • The receiver knows when new data is coming by looking for the start bit (digital 0 on the RxD line). • After receiving the start bit, the receiver looks for 8 data bits, followed by a stop bit (digital high on the RxD line). • If the receiver does not see a stop bit at the correct time, it sets the Framing Error bit in the status register. • Transmitter and receiver use the same internal clock rate, called the Baud Rate. • At 9600 baud (the speed used by D-Bug12), it takes 1/9600 second for one bit, 10/9600 second, or 1.04 ms, for one byte. Asynchronous Serial ProtocolsEE 308 Spring 2011 • The SCI interface on the MC9S12 uses voltage levels of 0 V and +5 V. The RS-232 standard uses voltage levels of +12 V and -12 V. – The Dragon12-Plus board uses a Maxim MAX232A chip to shift the TTL levels from the MC9S12 to the RS-232 levels necessary for connecting to a standard serial port. 0 V from the SCI is converted to +12 V on the DB-9 connector and +5 V from the SCI is converted to -12 V on the DB-9 connector. – The RS-232 standard can work on cables up to a length of 50 feet. • Another asynchronous standard is RS-485. Dragon12-Plus board can use SCI1 in RS- 485 mode – RS-485 is a two-wire differential asynchronous protocol – Multiple devices can connect to the same two wires – Only one device on the RS-485 bus can transmit; all the other devices are in receive mode – The Dragon12-Plus DS75176 differential-to-single ended converter to convert the single-ended SCI1 data to differential RS-485 data – Bit 0 of Port J determines if the RS-485 should be in receive mode or transmit mode – RS-485 can work with cables up to a length of 1,000 feet.EE 308 Spring 2011 Parity in Asynchronous Serial Transfers • The HCS12 can use a parity bit for error detection. – When enabled in SCI0CR1, the parity function uses the most significant bit for parity. – There are two types of parity – even parity and odd parity * With even parity, and even number of ones in the data clears the parity bit; an odd number of ones sets the parity bit. The data transmitted will always have an even number of ones. * With odd parity, and odd number of ones in the data clears the parity bit; an even number of ones sets the parity bit. The data transmitted will always have an odd number of ones. – The HCS12 can transmit either 8 bits or 9 bits on a single transfer, depending on the state of M bit of SCI0CR1. – With 8 data bits and parity disabled, all eight bits of the byte will be sent. – With 8 data bits and parity enabled, the seven least significant bits of the byte are sent; the MSB is replaced with a parity bit. – With 9 data bits and parity disabled, all eight bits of the byte will be sent, and an additional bit can be sent in the sixth bit of SCI0DRH. * It usually does not make sense to use 9 bit mode without parity. – With 9 data bits and parity enabled, all eight bits of the byte are sent; the ninth bit is the parity bit, which is put into the MSB of SCI0DRH in the receiver.EE 308 Spring 2011 Asynchronous Data Transfer • The HCS12 has two asynchronous serial interfaces, called the SCI0 and SCI1 (SCI stands for Serial Communications Interface) • SCI0 is used by D-Bug12 to communicate with the host PC • When using D-Bug12 you normally cannot independently operate SCI0 (or you will lose your communications link with the host PC) • The SCI0 TxD pin is bit 1 of Port S; the SCI1 TxD pin is bit 3 of Port S. • The SCI0 RxD pin is bit 0 of Port S; the SCI1 RxD pin is bit 2 of Port S. • In asynchronous data transfer, serial data is transmitted by shifting out of a transmit shift register into a receive shift register.EE 308 Spring 2011 Timing in Asynchronous Data Transfers • The BAUD rate is the number of bits per second. • Typical baud rates are 1200, 2400, 4800, 9600, 19,200, and 115,000 • At 9600 baud the transfer rate is 9600 bits per second, or one bit in 104 µs. • When not transmitting the
View Full Document