msp430 teaching materialshugo/micros/chapt7_comm.pdfdesarrollado con el objetivo principal de...
Post on 27-Mar-2020
12 Views
Preview:
TRANSCRIPT
15/01/2013
1
UBI
>> Contents
Capítulo 7Comunicaciones
Introducción
MSP430 Teaching Materials
Texas Instruments IncorporatedUniversity of Beira Interior (PT)
Pedro Dinis Gaspar, António Espírito Santo, Bruno Ribeiro, Humberto SantosUniversity of Beira Interior, Electromechanical Engineering Department
www.msp430.ubi.pt
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
UBI
>> Contents2
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Contents
� Introduction
� Communications system model
� Transmission mode
� Serial communications
� Synchronous and asynchronous serial communications
� Peripheral Interface Serial (SPI) protocol
� I2C (Inter-Integrated Circuit) protocol
� MSP430 communications interfaces
� Quiz
15/01/2013
2
UBI
>> Contents3
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Introduction
� Una característica importante de los sistemas basados en microprocesadores modernos es su capacidad de comunicación, es decir, su capacidad para intercambiar información con otros sistemas en el medio ambiente circundante;
� A bajo nivel, las interfaces de comunicación se utilizan para descargar una actualización de firmware o para establecer las configuraciones locales (por ejemplo, características encender o apagar), entre otras tareas;
� En un nivel superior, interfaces de comunicación se utilizan para intercambiar información en aplicaciones distribuidas.
UBI
>> Contents4
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Communications system model (1/2)
� Dispositivos de comunicación digital:
� Transmisor: Tiene la tarea de poner la información en el formato adecuado para su posterior transmisión;
� Receptor: Es el encargado de recoger el mensaje que se ha enviado y extraer la información original;
� Medio de comunicación: El medio físico a través del cual fluye la información y se implementa habitualmente como:
• Par de cable trenzado;
• Cable de fibra óptica;
• Transmisión por radiofrecuencia.
15/01/2013
3
UBI
>> Contents5
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Communications system model (2/2)
� Dispositivos de un sistema de comunicación digital:
� DTE: Data Terminal Equipment;
� DCE: Data Communications Equipment.
DTE DTEDCEDCE
Transmission medium
Transmitter Receiver
TransmitterReceiver
UBI
>> Contents6
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Transmission mode (1/5)
� La comunicaciones entre dispositivos digitales pueden ser divididos en dos tiempos:
� Comunicaciones paralelas;
� Comunicaciones seriales.
� Comunicaciones paralelas:
� El medio físico de transmisión tiene líneas independientes de señal en un número igual a los bits de la palabra digital transmitida;
� La información transmitida en cualquier instante dado, es la palabra de datos formada por los niveles lógicos en las líneas de señal diferentes.
15/01/2013
4
UBI
>> Contents7
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Transmission mode (2/5)
� Comunicaciones paralelas:
� Ejemplo: Carácter ASCII “W” en una transmisión paralela.
Flujo de la información
UBI
>> Contents8
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Transmission mode (3/5)
� Comunicación serial:
� El medio físico de transmisión sólo necesita una línea de señal;
� La información transmitida es proporcionada por el transmisor como una secuencia de bits, enviado a la razón establecida entre el transmisor y el receptor;
� Se necesita información adicional para permitir la sincronización entre el receptor y el transmisor:
• Bit de inicio: se añade al inicio de la información transmitida, de modo que el receptor puede identificar el inicio de una nueva transmisión;
• Bit de paro(s): Añadido a la final de la información transmitida para indicar que el valor de los datos se ha completado.
15/01/2013
5
UBI
>> Contents9
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Transmission mode (4/5)
� Comunicación serial:
� Ejemplo: Carácter ASCII “W” de transmisión serial:
UBI
>> Contents10
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Transmission mode (5/5)
� Ventajas y desventajas de las comunicaciones seriales y paralelas:
Característica Paralela Serial
Bus line One line per bit One line
SequenceAll bits of one word
simultaneouslySequence of bits
Transmissionrate
High Low
Bus length Short distances Short and long distances
Cost High Low
Criticalcharacteristics
Synchronisation betweenthe different bits isdemanding
Asynchronous transmission needs start and stop bits
Synchronous transmission needs some other synchronisation
15/01/2013
6
UBI
>> Contents11
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Serial communications (1/3)
� El bit de inicio identifica el inicio de una transferencia de datos y se genera una transición de alto a bajo en el bus;
� Tras el bit de inicio son los bits de datos. En este ejemplo, el código ASCII para la transferencia de texto utiliza siete bits de datos;
� La comprobación de errores de bit (bit de paridad) se envía después de los bits de datos;
� Para finalizar la transmisión, uno o dos bits de parada se emiten;
� A partir de siete bits de datos, el mensaje completo puede utilizar uno o dos bits de paro. Si se usan ocho bits de datos, un bit de paro sólo está disponible para la transmisión.
UBI
>> Contents12
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Serial communications (2/3)
� Bit de paridad:
� Se utiliza para verificar la integridad de la información transmitida;
� El bit se agrega por el transmisor e indica si la suma total de los números "1" en el mensaje de datos es par o impar;
� Las transmisiones pueden ser configurados para paridad par o impar.
15/01/2013
7
UBI
>> Contents13
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Serial communications (3/3)
� Ejemplo de baud rate:
� La transmisión de la “W”:
• El caracter usa siete bits de datos;
• Cuatro bits son usados para control, haciendo un total de 11 bits.
• Esto corresponde a 11 bauds;
• Si los caracteres son transmitidos a una razón de 10 caracteres por segundo, el baud rate sería:
10x11 = 1100 baud/s.
UBI
>> Contents14
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Synchronous and asynchronous serial communications (1/2)
� Las comunicaciones seriales pueden ser:
� Asíncrono: donde la tasa de transmisión (baud rate) está fijado por el transmisor y el receptor funcionan en la mismo baud rate de transmisión, utilizando el bit de inicio de transmisión para sincronizar el inicio de un nuevo mensaje;Síncrono: donde hay una señal de sincronización de reloj independiente conectado entre el receptor y el transmisor.
� Síncrono: donde hay una señal de sincronización de reloj independiente conectado entre el receptor y el transmisor.
� Comunicaciones síncronas:
� Normalmente una unidad asume el papel de maestro y uno o más de las otras unidades tomar el papel de esclavos;
� La señal de reloj generada por el maestro es utilizado por las unidades esclavas para transferir datos en /hacia los registros TX y RX;
� Es posible que un dispositivo para transmita y reciba simultáneamente.
15/01/2013
8
UBI
>> Contents15
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Synchronous and asynchronous serial communications (2/2)
� Comunicaciones asíncronas:
� Caracterizada por la ausencia de cualquier señal de reloj desincronización entre las unidades;
� La transmisión en este modo no permite la transmisión yrecepción simultáneas, es decir, cuando un dispositivotransmite los otros dispositivos sólo escuchan.
UBI
>> Contents16
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Serial Peripheral Interface (SPI) protocol(1/2)
� El bus de Interfaz Serial de Periféricos (Serial PeripheralInterface SPI) es un estándar para la comunicaciónserial síncrona.
� Desarrollado por Motorola;
� Funciona en mod full duplex;
� Relación Maestro / esclavo;
� Las comunicaciones son
Siempre iniciadas por el maestro.
� Bajo costo.
15/01/2013
9
UBI
>> Contents17
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Peripheral Interface Serial (SPI) protocol(2/2)
� Soporta un solo maestro;
� Puede soportar más de un esclavo;
� A corta distancia entre dispositivos, por ejemplo, en unaplaca de circuito impreso (PCB);
� Se observa especial atención en la polaridad y la fase dela señal de reloj;
� El maestro envía los datos en un filo de reloj y lee losdatos en el otro filo. Por lo tanto, se puede enviar /recibir al mismo tiempo.
UBI
>> Contents18
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
I2C (Inter-Integrated Circuit) protocol (1/3)
� Bus serial síncrono de computadora multi maestro;
� Inventado por Philips semiconductores;
� Desarrollado con el objetivo principal de establecer vínculos entre los circuitos integrados y para conectar periféricos de baja velocidad;
� Basado en un dos líneas bidireccionales con compuertas de colector abierto conectadas con resistores:
• SDA: Serial Data;
• SCL: Serial clock.
� Los voltajes típicos usados son de +5.0 V o +3.3 V, sin embargo otros voltajes son posibles.
15/01/2013
10
UBI
>> Contents19
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
I2C (Inter-Integrated Circuit) protocol (2/3)
� Las comunicaciones son siempre iniciados y completados por el maestro, el cual es responsable de generar la señal de reloj;
� En aplicaciones más complejas, I2C puede funcionar en modo de multi maestro;
� La selección del esclavo por el maestro es realizado usando la dirección de 7 bits del esclavo destino;
� El maestro (en modo de transmisión) envía:
� Bit de inicio;
� La dirección de 7-bits del esclavo con el que se desea comunicar;
� Con un bit se determina
� Con un solo bit representa si desea escribir (0) o para leer (1) desde el esclavo;
� El esclavo de destino responde con su dirección.
UBI
>> Contents20
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
I2C (Inter-Integrated Circuit) protocol (3/3)
� Ejemplo de un sistema de comunicación I2C:
15/01/2013
11
UBI
>> Contents21
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
MSP430 communications interfaces (1/2)
� Equipado con tres interfaces seriales:
� USART (Universal Synchronous/Asynchronous Receiver/Transmitter):
• UART mode;
• SPI mode;
• I2C (on ‘F15x/’F16x only).
� USCI (Universal Serial Communication Interface):
• UART with Lin/IrDA support;
• SPI (Master/Slave, 3 and 4 wire modes);
• I2C (Master/Slave, up to 400 kHz).
� USI (Universal Serial Interface):
• SPI (Master/Slave, 3 & 4 wire mode);
• I2C (Master/Slave, up to 400 kHz).
UBI
>> Contents22
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
MSP430 communications interfaces (2/2)
� Comparación entre los módulos de comunicaciones
USART USCI USI
UART:- Only one modulator- n/a- n/a- n/a
UART:- Two modulators support
n/16 timings- Auto baud rate detection- IrDA encoder & decoder- Simultaneous USCI_A and
USCI_B (2 channels)
SPI:- Only one SPI available- Master and Slave Modes- 3 and 4 Wire Modes
SPI:- Two SPI (one on each
USCI_A and USCI_B)- Master and Slave Modes- 3 and 4 Wire Modes
SPI:- Only one SPI available- Master and Slave Modes
I2C: (on ‘15x/’16x only)- Master and Slave Modes- up to 400kbps
I2C:- Simplified interrupt usage- Master and Slave Modes- up to 400kbps
I2C:- SW state machine needed- Master and Slave Modes
15/01/2013
12
UBI
>> Contents23
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (1/6)
� 1. In the parallel communication transmission mode:
(a) The data is transferred more slowly;
(b) Each bit of the data has its own line;
(c) All of above;
(d) None of above.
� 2. In the serial communication transmission mode:
(a) The data bits arrive sequentially;
(b) The digital data is transferred faster;
(c) All of above;
(d) None of above.
UBI
>> Contents24
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (2/6)
� 3. The serial transmission mode is the most popular digital data communications method because:
(a) Higher bit transfer rates are achieved;
(b) It is cheaper to implement than parallel transmission mode;
(c) All of above;
(d) None of above.
� 4. In asynchronous serial transmission communications, the frame must include:
(a) Start and stop bits.
(b) Parity bit.
(c) All of above;
(d) None of above.
15/01/2013
13
UBI
>> Contents25
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (3/6)
� 5. Even parity means that an additional bit is:
(a) Added to the data to make the sum of the “1” bits even;
(b) Subtracted from the data to make the sum of the “1” bits even;
(c) All of above;
(d) None of above.
� 6. A USART is used:
(a) Only for asynchronous transmissions;
(b) Only for synchronous transmissions;
(c) In parallel transmission communications;
(d) In serial transmission communications.
UBI
>> Contents26
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (4/6)
� 7. Synchronous communication performed between two USART requires:
(a) A common clock either in the transmitter or the receiver;
(b) No common clock;
(c) An independent clock in the transmitter;
(d) An independent clock in the receiver.
� 8. Asynchronous communication between two USARTs requires:
(a) A common clock in the transmitter and the receiver;
(b) An independent clock in the transmitter and the receiver;
(c) A common clock in the transmitter or the receiver;
(d) An independent clock in the transmitter or the receiver.
15/01/2013
14
UBI
>> Contents27
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (5/6)
� 9. I2C is a bus:
(a) Synchronous with a master and a slave where both can be the transmitter or receiver;
(b) Where the master generates the clock;
(c) All of above;
(d) None of above.
UBI
>> Contents28
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (6/6)
� Answers:
1. (b) Each bit of the data has its own line.
2. (a) The data bits arrive sequentially.
3. (c) All of above.
4. (c) All of above.
5. (a) Added to the data to make the sum of the “1” bits even.
6. (d) In serial transmission communications.
7. (a) A common clock either in the transmitter or the receiver.
8. (b) An independent clock in the transmitter and the receiver.
9. (d) None of above.
15/01/2013
15
UBI
>> Contents29
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
UBI
>> Contents
Capítulo 7Comunicaciones
Módulo USART
MSP430 Teaching Materials
Texas Instruments IncorporatedUniversity of Beira Interior (PT)
Pedro Dinis Gaspar, António Espírito Santo, Bruno Ribeiro, Humberto SantosUniversity of Beira Interior, Electromechanical Engineering Department
www.msp430.ubi.pt
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
15/01/2013
16
UBI
>> Contents31
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Contents
� MSP430 communications interfaces
� USART module introduction
� USART operation: UART mode
� USART operation: SPI mode
� USART registers (UART and SPI modes)
� Quiz
UBI
>> Contents32
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART module introduction (1/2)
� The USART (Universal Synchronous/AsynchronousReceiver/Transmitter) este módulo esta basado para comunicaciones seriales soportando comunicaciones (RS232) y asíncronas (SPI).
� El módulo USART esta disponible en los dispositivos 4xx:
� MSP430x42x y MSP430x43x: un módulo;
� MSP430x44x y MSP430FG461x: Dos módulos.
15/01/2013
17
UBI
>> Contents33
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART module introduction (2/2)
� El soporte del USART:
• Modos de operación baja potencia (con auto inicio);
• Modo UART o SPI (I2C solo en ‘F15x/’F16x);
• Buffer doble TX/RX;
• Generador de baud rate;
• Habilita DMA;
• Detección de errores.
UBI
>> Contents34
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (1/13)
� Transmite y recibe caracteres de forma asíncrona;
� La sincronización de cada carácter se basa en la selección de baud rate seleccionada;
� El transmisor y el receptor usa la misma frecuencia de reloj que llevan el mismo baud rate;
15/01/2013
18
UBI
>> Contents35
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (2/13)
� Proceso de Inicialización / reconfiguración recomendada:
� Poner SWRST (BIS.B #SWRST,&UxCTL);
� Inicializa todos los registros del USART con SWRST = 1 (incluyendo UxCTL);
� Habilita el modo USART vía los SFRs Mex (URXEx y/o UTXEx);
� Limpia por software SWRST (BIC.B #SWRST,&UxCTL);
� Habilita las interrupciones (opcional) vía los SFRs Iex(URXIEx y/o UTXIEx);
UBI
>> Contents36
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (3/13)
� El formato del carácter se especifica como sigue:
� Bit de inicio;
� Siete u ocho bits de datos;
� Bit de paridad impar/par;
� Bit de dirección (modo de bit de dirección);
� Uno o dos bits de paro.
15/01/2013
19
UBI
>> Contents37
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (6/13)
� Detección de error automático:
� El supresor de Glitch previene que la USART se inicie accidentalmente;
� Cualquier pulso corto en UCxRXC menor al tiempo de glitch(aproximadamente 30 ns).
� Error de trama FE: Se activa si el bit de paro es omitido de la trama recibida;
� Error de paridad PE: Se pone si la paridad es diferente de la trama recibida;
� Error de desbordamiento OE: Se pone si UxRXBUF es sobrescrita;
� Condición de ruptura BRK: Se pone si todos los bits en la trama recibida =0;
UBI
>> Contents38
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (7/13)
� Habilitado el receptor de la USART se activa el bit URXEx:
� El buffer del datos recibidos, UxRXBUF, contiene el carácter movido del registro de corrimiento RX después de que el carácter ha sido recibido.
15/01/2013
20
UBI
>> Contents39
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (8/13)
� Habilitado el transmisor de la USART con el bit UTXEx:
� La transmisión es iniciado por escribir el dato a UxTXBUF;
� El valor del dato se mueve al registro de corrimiento del transmisor en el siguiente pulso de reloj después que éste se vacía.
UBI
>> Contents40
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (9/13)
� Generación del Baud rate del USART :
� El baud rate estándar se genera con generadores de frecuencia no convencionales.
� El módulo USART utiliza un pre-escalador / divisor y un modulador;
� El bit de temporización (BITCLK) de este módulo se permite que sea más pequeño que 1/3 de la señal de reloj, BRCLK.
15/01/2013
21
UBI
>> Contents41
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (10/13)
� Generación del Baud rate del USART(continuación):
� Bits de temporización:
• Implementación en dos etapas:
– Par el divisor BRCLK, el factor N esta dado por:
– Su parte entera es la primera fase del bit de tiempo;
– Su parte fraccionaria de este factor es el modulador;
– La nueva definición de N esta dado por:
baudrate
BRCLKN =
∑
−
=
+=1
0
1 n
i
im
nUxBRN
UBI
>> Contents42
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (11/13)
� Interrupción de la USART:
� Un vector de interrupciones para la transmisión y un vector para la recepción:
� Interrupción de la UART por transmisión:
• La bandera de interrupción UTXIFGx se pone el transmisor para indicar que UxTXBUF está listo para aceptar otro carácter;
• Una petición de interrupción también se genera si UTXIExy GIE se activan;
• El bit UTXIFGx se reinicia automáticamente si la solicitud de interrupción es atendida o si un carácter se escribe en UxTXBUF.
15/01/2013
22
UBI
>> Contents43
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (12/13)
� Interrupción de la USART(continuación):
� Interrupción de la UART por recepción:
• La bandera de interrupción URXIFGx se pone cada vez que se recibe un carácter y se cargan en UxRXBUF;
• Una petición de interrupción también se genera si URXIExy GIE se activan;
• URXIFGx y URXIEx se restablecen por una señal de reinicio del sistema o cuando SWRST PUC = 1;
• URXIFGx se reinicia automáticamente si la interrupción pendiente es atendida (cuando URXSE = 0) o cuando se lee UxRXBUF.
UBI
>> Contents44
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: UART mode (13/13)
� La facilidad de la detección del filo de inicio del receptor (URXSE bit). Deberá usarse cuando:
� BRCLK es la fuente del DCO;
� DCO esta apagado debido al modo de operación de bajo consumo.
15/01/2013
23
UBI
>> Contents
Ejemplo de comunicaciones seriales
//***************************************************************
// MSP430G2xx3 Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK
//
// Description: Echo a received character, RX ISR used. Normal mode is LPM0.
// USCI_A0 RX interrupt triggers TX Echo.
// Baud rate divider with 1MHz = 1MHz/9600 = ~104.2
// ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
//
// MSP430G2xx3
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.2/UCA0TXD|------------>
// | | 9600 - 8N1
// | P1.1/UCA0RXD|<------------
//
// D. Dang
// Texas Instruments Inc.
// February 2011
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//*************************************************************
45
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
UBI
>> Contents
Ejemplo de comunicaciones seriales
#include "msp430g2553.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; //
**Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
_BIS_SR(GIE);
while(1);
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
46
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
15/01/2013
24
UBI
>> Contents47
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: SPI mode (1/8)
� Serial data transmitted and received by multiple devices using a shared clock provided by the master;
� Three or four signals are used for SPI data exchange:
� SIMO: Slave In, Master Out;
� SOMI Slave Out, Master In;
� UCLK USART SPI clock;
� STE slave transmit enable (controlled by the master).
UBI
>> Contents48
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: SPI mode (2/8)
� USART initialization/re-configuration process:
� Set SWRST (BIS.B #SWRST,&UxCTL);
� Initialize all USART registers with SWRST = 1 (including UxCTL);
� Enable USART module via the MEx SFRs (URXEx and/or UTXEx);
� Clear SWRST via software (BIC.B #SWRST,&UxCTL);
� Enable interrupts (optional) via the IEx SFRs (URXIEx and/or UTXIEx);
15/01/2013
25
UBI
>> Contents49
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: SPI mode (3/8)
� Define mode: Master or Slave;
� Enable SPI transmit/receive, USPIEx;
� State diagram of transmit enable for SPI master mode:
UBI
>> Contents50
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: SPI mode (4/8)
� Enable SPI transmit/receive, USPIEx;
� State diagram of transmit enable for SPI slave mode:
15/01/2013
26
UBI
>> Contents51
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: SPI mode (5/8)
� Enable SPI transmit/receive, USPIEx;
� State diagram of receive enable for SPI master mode:
UBI
>> Contents52
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: SPI mode (6/8)
� Enable SPI transmit/receive, USPIEx;
� State diagram of receive enable for SPI slave mode:
15/01/2013
27
UBI
>> Contents53
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: SPI mode (7/8)
� Define serial clock control:
� UCLK is provided by the master on the SPI bus.
• MM = 1: BITCLK is provided by the USART baud rate generator on the UCLK;
• MM = 0: USART clock is provided on the UCLK pin by the master (baud rate generator disable);
• The SPI receiver and transmitter operate in parallel and use the same clock source for data transfer.
� Define serial clock polarity (CKPL bit) and phase (CKPH bit);
UBI
>> Contents54
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART operation: SPI mode (8/8)
� USART interrupts:
� One interrupt vector for transmission and one interrupt vector for reception:
� UART transmit interrupt operation:
• UTXIFGx interrupt flag is set by the transmitter to indicate that UxTXBUF is ready to accept another character;
• An interrupt request is generated if UTXIEx and GIE are also set;
• UTXIFGx is automatically reset if the interrupt request is serviced or if a character is written to UxTXBUF.
15/01/2013
28
UBI
>> Contents55
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (1/11)
� In this section, the register bit definitions are provided for both USART peripheral interfaces:
� Asynchronous UART mode;
� Synchronous SPI mode.
� The registers common to both modes are described simultaneously, taking into account that some of them are represented by the same mnemonic, only differentiated by the register number (“UART” for UART mode and “SPI” for SPI mode);
� The registers used exclusively for one mode are presented separately.
UBI
>> Contents56
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (2/11)
� UxCTL, USART Control RegisterMode 7 6 5 4 3 2 1 0
UART PENA PEV SPB CHAR LISTEN SYNC MM SWRST SPI Unused Unused I2C(1) CHAR LISTEN SYNC MM SWRST
Bit UART mode description SPI mode description
7 PENA Parity enable when PENA = 1Parity bit is generated (UTXDx) and expected (URXDx).
U Unused
6 PEV Parity select:PEV = 0 ⇒ Odd parityPEV = 1 ⇒ Even parity
Unused
5 SPB Stop bit select:SPB = 0 ⇒ One stop bitSPB = 1 ⇒ Two stop bits
I2C
I2C or SPI mode select when SYNC = 1.I2C = 0 ⇒ SPI modeI2C = 1 ⇒ I2C mode
4 CHAR Character length:CHAR = 0 ⇒ 7-bit dataCHAR = 1 ⇒ 8-bit data
C As UART mode
3 LISTEN Listen enable when LISTEN = 1. The transmit signal is internally fed back to the receiver.
L As UART mode
2 SYNC Synchronous mode enable:SYNC = 0 ⇒ UART modeSYNC = 1 ⇒ SPI Mode
SNC
As UART mode
1 MM Multiprocessor mode selectMM = 0 ⇒ Idle-line multiprocessor protocolMM = 1 ⇒ Address-bit multiprocessor protocol
MM
Master mode:MM = 0 ⇒ USART is slaveMM = 1 ⇒ USART is master
0 SWRST Software reset enable:SWRST = 0 ⇒ Disabled. USART reset released for operationSWRST = 1 ⇒ Enabled. USART logic held in reset state
SWRST
As UART mode
15/01/2013
29
UBI
>> Contents57
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (3/11)
� UxTCTL, USART Transmit Control RegisterMode 7 6 5 4 3 2 1 0
UART Unused CKPL SSELx URXSE TXWAKE Unused TXEPT
SPI CKPH CKPL SSELx Unused Unused STC TXEPT
Bit UART mode description SPI mode description
7 Unused CKPH
6 CKPL Clock polarity select:CKPL = 0 ⇒ UCLKI = UCLKCKPL = 1 ⇒ UCLKI = inverted UCLK
CKPL Clock polarity select:CKPL = 0 ⇒ UCLKI = The inactive state is low.CKPL = 1 ⇒ UCLKI = The inactive state is high.
5-4 SSELx BRCLK source clock:SSEL1 SSEL0 = 00 ⇒ UCLKISSEL1 SSEL0 = 01 ⇒ ACLKSSEL1 SSEL0 = 10 ⇒ SMCLKSSEL1 SSEL0 = 11 ⇒ SMCLK
SSELx BRCLK source clock:SSEL1 SSEL0 = 00 ⇒ External UCLK (slave mode only)SSEL1 SSEL0 = 01 ⇒ ACLK (master mode only)SSEL1 SSEL0 = 10 ⇒ SMCLK (master mode only)SSEL1 SSEL0 = 11 ⇒ SMCLK (master mode only)
3 URXSE UART receive start-edge enable when URXSE = 1 Unused
2 TXWAKE Transmitter wake:TXWAKE = 0 ⇒ Next frame transmitted is dataTXWAKE = 1 ⇒ Next frame transmitted is an address
Unused
1 Unused STC Slave transmit control:STC = 0 ⇒ 4-pin SPI mode: STE enabled.STC = 1 ⇒ 3-pin SPI mode: STE disabled.
0 TXEPT Transmitter empty flag:TXEPT = 0 ⇒ UART is transmitting data and/or data is
waiting in UxTXBUFTXEPT = 1 ⇒ Transmitter shift register and UxTXBUF are
empty or SWRST=1
TXEPT Transmitter empty flag:TXEPT = 0 ⇒ UART is transmitting data and/or data is
waiting in UxTXBUFTXEPT = 1 ⇒ UxTXBUF and TX shift register are empty
UBI
>> Contents58
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (4/11)
� UxRCTL, USART Receive Control RegisterMode 7 6 5 4 3 2 1 0
UART FE PE OE BRK URXEIE URXWIE RXWAKE RXERR
SPI FE Unused OE Unused Unused Unused Unused Unused
Bit UART mode description SPI mode description
7 FE Framing error flag:= 0 ⇒ No error= 1 ⇒ Character received with low stop bit
FE Master mode framing error flag: (MM = 1, STC = 0)= 0 ⇒ No conflict detected= 1 ⇒ Bus conflict (STE’s negative edge)
6 PE Parity error flag:= 0 ⇒ No error= 1 ⇒ Character received with parity error
Unused
5 OE Overrun error flag:= 0 ⇒ No error= 1 ⇒ A character was transferred into UxRXBUF before the
previous character was read.
OE As UART mode
4 BRK Break detect flag:= 0 ⇒ No break condition= 1 ⇒ Break condition occurred
Unused
3 URXEIE Receive erroneous-character interrupt-enable:= 0 ⇒ Err. characters rejected= 1 ⇒ Err. characters received
Unused
2 URXWIE Receive wake-up interrupt-enable:= 0 ⇒ All received characters set IFG= 1 ⇒ Received address characters set IFG
Unused
1 RXWAKE Receive wake-up flag:= 0 ⇒ Received character is data= 1 ⇒ Received character is an address
Unused
0 RXERR Receive error flag:= 0 ⇒ No receive errors detected= 1 ⇒ Receive error detected
Unused
15/01/2013
30
UBI
>> Contents59
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (5/11)
� UxBR0, USART Baud Rate Control Register 0
� UxBR1, USART Baud Rate Control Register 1
Mode 7 6 5 4 3 2 1 0
UART / SPI 27 26 25 24 23 22 21 20
Mode 7 6 5 4 3 2 1 0
UART / SPI 215 214 213 212 211 210 29 28
Bit UART mode description SPI mode description
7 UxBRx The valid baud-rate control range is 3 ≤UxBR < 0FFFFh, where UxBR = {UxBR1+UxBR0}.Unpredictable receive/transmit timing occurs if UxBR < 3.
UxBRx The baud-rate generator uses the content of {UxBR1+UxBR0} to set the baud rate.Unpredictable SPI operation occurs if UxBR < 2.
UBI
>> Contents60
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (6/11)
� UxMCTL, USART Modulation Control Register
� UxRXBUF, USART Receive Buffer Register
Mode 7 6 5 4 3 2 1 0
UART / SPI m7 m6 m5 m4 m3 m2 m1 m0
Bit UART mode description SPI mode description
7 UxMCTLx
Selects the modulation for BRCLK. UxMCTLx Not used in SPI mode and should be set to 00h.
Mode 7 6 5 4 3 2 1 0
UART / SPI 27 26 25 24 23 22 21 20
Bit UART mode description SPI mode description
7 UxRXBUFx The receive-data buffer is user accessible and contains the last received character from the receive shift register.Reading UxRXBUF resets the receive-error bits, the RXWAKE bit, and URXIFGx.In 7-bit data mode, UxRXBUF is LSB justified and the MSB is always cleared.
UxRXBUFx The receive-data buffer is user accessible and contains the last received character from the receive shift register.Reading UxRXBUF resets the OE bit and URXIFGx flag.In 7-bit data mode, UxRXBUF is LSB justified and the MSB is always cleared.
15/01/2013
31
UBI
>> Contents61
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (7/11)
� UxTXBUF, USART Transmit Buffer RegisterMode 7 6 5 4 3 2 1 0
UART / SPI 27 26 25 24 23 22 21 20
Bit UART mode description SPI mode description
7 UxTXBUFx The transmit data buffer is useraccessible and holds the datawaiting to be moved into thetransmit shift register andtransmitted on UTXDx.
Writing to the transmit data bufferclears UTXIFGx.
The MSB of UxTXBUF is not used for7-bit data and is cleared.
UxTXBUFx The transmit data buffer is useraccessible and contains current datato be transmitted.
When seven-bit character-length isused, the data should be MSBjustified before being moved intoUxTXBUF.
Data is transmitted MSB first.Writing to UxTXBUF clears UTXIFGx.
UBI
>> Contents62
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (8/11)
� ME1, Module Enable Register 1
� ME2, Module Enable Register 2
Bit UART mode description SPI mode description
7 UTXE0 USART0 transmit enable:UTXE0 = 0 ⇒ Module not enabledUTXE0 = 1 ⇒ Module enabled
6 URXE0 USART0 receive enable:URXE0 = 0 ⇒ Module not enabledURXE0 = 1 ⇒ Module enabled
USPIE0 USART0 SPI enable:USPIE0 = 0 ⇒ Module not enabledUSPIE0 = 1 ⇒ Module enabled
Mode 7 6 5 4 3 2 1 0
UART UTXE0 URXE0
SPI USPIE0
Mode 7 6 5 4 3 2 1 0
UART UTXE1 URXE1
SPI USPIE1
Bit UART mode description SPI mode description
5 UTXE1 USART1 transmit enable:UTXE1 = 0 ⇒ Module not enabledUTXE1 = 1 ⇒ Module enabled
4 URXE1 USART1 receive enable:URXE1 = 0 ⇒ Module not enabledURXE1 = 1 ⇒ Module enabled
USPIE1 USART1 SPI enable:USPIE1 = 0 ⇒ Module not enabledUSPIE1 = 1 ⇒ Module enabled
15/01/2013
32
UBI
>> Contents63
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (9/11)
� IE1, Interrupt Enable Register 1
� IE2, Interrupt Enable Register 2
Bit UART mode description SPI mode description
7 UTXIE0 USART0 UTXIFG0 transmit interrupt enable:UTXIE0 = 0 ⇒ Interrupt not enabledUTXIE0 = 1 ⇒ Interrupt enabled
UTXIE0 As UART mode
6 URXIE0 USART0 URXIFG0 receive interrupt enable:URXIE0 = 0 ⇒ Interrupt not enabledURXIE0 = 1 ⇒ Interrupt enabled
URXIE0 As UART mode
Mode 7 6 5 4 3 2 1 0
UART / SPI UTXIE0 URXIE0
Mode 7 6 5 4 3 2 1 0
UART / SPI UTXIE1 URXIE1
Bit UART mode description SPI mode description
7 UTXIE1 USART1 UTXIFG1 transmit interrupt enable:UTXIE1 = 0 ⇒ Interrupt not enabledUTXIE1 = 1 ⇒ Interrupt enabled
UTXIE1 As UART mode
6 URXIE1 USART1 URXIFG1 receive interrupt enable:URXIE1 = 0 ⇒ Interrupt not enabledURXIE1 = 1 ⇒ Interrupt enabled
URXIE1 As UART mode
UBI
>> Contents64
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (10/11)
� IFG1, Interrupt Flag Register 1Mode 7 6 5 4 3 2 1 0
UART / SPI UTXIFG0 URXIFG0
Bit UART mode description SPI mode description
7 UTXIFG0 USART0 transmit interrupt flag. UTXIFG0 is set when U0TXBUF is empty.UTXIFG0 = 0 ⇒ No interrupt pendingUTXIFG0 = 1 ⇒ Interrupt pending
UTXIFG0 As UART mode
6 URXIFG0 USART0 receive interrupt flag. URXIFG0 is set when U0RXBUF has received a complete character.URXIFG0 = 0 ⇒ No interrupt pendingURXIFG0 = 1 ⇒ Interrupt pending
URXIFG0 As UART mode
15/01/2013
33
UBI
>> Contents65
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USART registers (UART and SPI modes) (11/11)
� IFG2, Interrupt Flag Register 2Mode 7 6 5 4 3 2 1 0
UART / SPI UTXIFG1 URXIFG1
Bit UART mode description SPI mode description
7 UTXIFG1 USART1 transmit interrupt flag. UTXIFG1 is set when U1TXBUF is empty.UTXIFG1 = 0 ⇒ No interrupt pendingUTXIFG1 = 1 ⇒ Interrupt pending
UTXIFG1 As UART mode
6 URXIFG1 USART1 receive interrupt flag. URXIFG1 is set when U1RXBUF has received a complete character.URXIFG1 = 0 ⇒ No interrupt pendingURXIFG1 = 1 ⇒ Interrupt pending
URXIFG1 As UART mode
UBI
>> Contents66
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (1/5)
� 1. The USART supports the following communication modes:
(a) UART and I2C;
(b) SPI and I2C;
(c) UART and SPI;
(d) None of above.
� 2. The USART module has:
(a) One SPI module;
(b) Two SPI modules;
(c) Three SPI modules;
(d) None of the above.
15/01/2013
34
UBI
>> Contents67
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (2/5)
� 3. The USART:
(a) Transmits and receives characters synchronously;
(b) Transmits characters synchronously and receives characters asynchronously;
(c) Transmits characters asynchronously and receives characters synchronously;
(d) Transmits and receives characters asynchronously.
� 4. The USART character format is composed of:
(a) {Start bit, Seven data bits, Parity bit, Stop bit};
(b) {Start bit, Eight data bits, Parity bit, Stop bits};
(c) {Start bit, Seven data bits, Parity bit, Address bit; Stop bit};
(d) Each of the above is possible.
UBI
>> Contents68
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (3/5)
� 5. The asynchronous communication formats available to the USART module are:
(a) Idle-line multiprocessor communication protocol;
(b) Address bit multiprocessor communication protocol;
(c) All of above;
(d) None of above.
� 6. The automatic error detection recognizes:
(a) Framing, Parity, Receive Overrun and Break condition errors;
(b) Framing and Parity errors;
(c) Receive Overrun and Break condition errors;
(d) Framing, Parity, Receive Overrun errors.
15/01/2013
35
UBI
>> Contents69
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (4/5)
� 7. The serial clock control in SPI mode when MM = 1 is provided by the:
(a) UCLK pin on the master;
(b) BITCLK USART baud rate generator on the UCLK;
(c) All of above;
(d) None of above.
UBI
>> Contents70
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (5/5)
� Answers
1. (c) UART and SPI.
2. (a) One SPI module.
3. (d) Transmits and receives characters asynchronously.
4. (d) Each of the above is possible.
5. (c) All of above.
6. (a) Framing, Parity, Receive Overrun and Break condition errors.
7. (b) BITCLK USART baud rate generator on the UCLK.
15/01/2013
36
UBI
>> Contents
Capítulo 7Comunicaciones
Módulo USCI
MSP430 Teaching Materials
Texas Instruments IncorporatedUniversity of Beira Interior (PT)
Pedro Dinis Gaspar, António Espírito Santo, Bruno Ribeiro, Humberto SantosUniversity of Beira Interior, Electromechanical Engineering Department
www.msp430.ubi.pt
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
UBI
>> Contents72
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Contents
� MSP430 communications interfaces
� USCI module introduction
� USCI operation: UART mode
� USCI operation: SPI mode
� USCI operation: I2C mode
� USCI registers: UART, SPI and I2C modes
� Lab10b: USCI echo test
� Quiz
15/01/2013
37
UBI
>> Contents73
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI module introduction (1/3)
� Although supporting UART, SPI and I2C, the USCI (Universal Serial Communication Interface) module is a communications interface specially designed to interconnect with high-speed industrial protocols:
� LIN (Local interconnect Network), used for low-cost modules in cars e.g. door modules, alarms, rain-sensors;
� IrDA (Infrared Data Association).
� The USCI module is available in the following devices:
• MSP430F5xx;
• MSP430F4xx and MSP430FG41xx;
• MSP430F2xx.
UBI
>> Contents74
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI module introduction (2/3)
� The USCI module supports:
� Low power operating modes (with auto-start);
� Two individual blocks:
• USCI_A: UART and SPI;
• USCI_B: SPI and I2C.
� Double buffered TX/RX;
� Baud rate/bit clock generator:
• With auto-baud rate detect;
• Flexible clock source.
� RX glitch suppression;
� DMA enabled;
� Error detection.
15/01/2013
38
UBI
>> Contents75
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI module introduction (3/3)
� USCI block diagram:
UBI
>> Contents76
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (1/9)
� Flexible interface:
� 3- or 4-pin SPI;
� 7- or 8-bit data length;
� Master or slave;
� LSB or MSB first.
� S/W configurable clock phase and polarity;
� Programmable SPI master clock;
� Double buffered TX/RX;
� Interrupt driven TX/RX (USCI_A and USCI_B share TX and RX vector);
� Direct Memory Address ( DMA) enabled;
� LPMx operation.
15/01/2013
39
UBI
>> Contents77
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (2/9)
� USCI module: SPI mode block diagram:
UBI
>> Contents78
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (3/9)
� USCI module: SPI connections:
15/01/2013
40
UBI
>> Contents79
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (4/9)
� Serial data transmitted and received by multiple devices using a shared clock provided by the master;
� Three or four signals are used for SPI data exchange:
� UCxSIMO: Slave in, master out;
� UCxSOMI: Slave out, master in;
� UCxCLK: USCI SPI clock;
� UCxSTE: Slave transmit enable:
• Enables a device to receive and transmit data and is controlled by the master;
• 4 wire master, senses conflicts with other master(s);
• In 4 wire slave, externally controls TX and RX.
UBI
>> Contents80
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (5/9)
� USCI initialization/re-configuration process:
� Set UCSWRST (BIS.B #UCSWRST,&UCAxCTL1);
� Initialize all USCI registers with UCSWRST = 1 (including UCxCTL1);
� Configure ports;
� Clear UCSWRST via software (BIC.B #UCSWRST,&UCxCTL1);
� Enable interrupts (optional) via UCxRXIE and/or UCxTXIE.
15/01/2013
41
UBI
>> Contents81
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (6/9)
� Define the character format as presented earlier;
� Define mode: Master or Slave;
� Enable SPI transmit/receive clearing the UCSWRST bit;
� Define serial clock control:
� UCxCLK is provided by the master on the SPI bus;
� Configure serial clock polarity and phase (UCCKPL and UCCKPH bits).
UBI
>> Contents82
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (7/9)
� USCI interrupts:
� One interrupt vector for transmission and one interrupt vector for reception:
� SPI transmit interrupt operation:
• UCxTXIFG interrupt flag is set by the transmitter to indicate that UCxTXBUF is ready to accept another character;
• An interrupt request is generated if UCxTXIE and GIE are also set;
• UCxTXIFG is automatically reset if the interrupt request is serviced or if a character is written to UCxTXBUF.
15/01/2013
42
UBI
>> Contents83
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (8/9)
� USCI interrupts (continued):
� USCI receive interrupt operation:
• UCxRXIFG interrupt flag is set each time a character is received and loaded into UCxRXBUF;
• An interrupt request is also generated if UCxRXIE and GIE are set;
• UCxRXIFG and UCxRXIE are reset by a system reset PUC signal or when SWRST = 1;
• UCxRXIFG is automatically reset if the pending interrupt is serviced (when UCSWRST = 1) or when UCxRXBUF is read.
UBI
>> Contents84
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: SPI mode (9/9)
� USCI interrupts (continued):
SPI TX interrupt: SPI RX interrupt:
15/01/2013
43
UBI
>> Contents85
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (1/11)
� The I2C mode supports any master or slave I2C-compatible device (Specification v2.1);
� Each I2C device is recognized by a unique address and can operate as either a transmitter or a receiver, as well as either the master or the slave;
� A master initiates a data transfer and generates the clock signal SCL;
� Any device addressed by a master is considered a slave;
� Communication using the bi-directional serial data (SDA) and serial clock (SCL) pins;
UBI
>> Contents86
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (2/11)
� I2C mode block diagram:
15/01/2013
44
UBI
>> Contents87
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (3/11)
� I2C mode block diagram:
UBI
>> Contents88
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (4/11)
� Initialized using the sequence given earlier;
� I2C serial data:
� One clock pulse is generated by the master for each data bit transferred;
� Operates with byte data (MSB transferred first);
� The first byte after a START condition consists of a 7-bit slave address and the R/W bit:
• R/W = 0: Master transmits data to a slave;
• R/W = 1: Master receives data from a slave.
� The ACK bit is sent from the receiver after each byte on the 9th SCL clock.
15/01/2013
45
UBI
>> Contents89
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (5/11)
� I2C addressing modes (7-bit and 10-bit addressing modes);
� I2C module operating modes:
� Master transmitter;
� Master receiver;
� Slave transmitter;
� Slave receiver.
� Arbitration procedure is invoked if two or more master transmitters simultaneously start a transmission on the bus;
UBI
>> Contents90
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (6/11)
� I2C Clock generation and synchronization:
� SCL is provided by the master on the I2C bus;
� Master mode: BITCLK is provided by the USCI bit clock generator;
� Slave mode: the bit clock generator is not used.
15/01/2013
46
UBI
>> Contents91
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (7/11)
� I2C interrupts:
� One interrupt vector for transmission and one interrupt vector for reception;
� I2C transmit interrupt operation:
• UCBxTXIFG interrupt flag is set by the transmitter to indicate that UCBxTXBUF is ready to accept another character;
• An interrupt request is also generated if UCBxTXIE and GIE are set;
• UCBxTXIFG is automatically reset if a character is written to UCBxTXBUF or a NACK is received.
UBI
>> Contents92
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (8/11)
� I2C interrupts (continued):
� I2C receive interrupt operation:
• UCBxRXIFG interrupt flag is set each time a character is received and loaded into UCxRXBUF;
• An interrupt request is also generated if UCBxRXIE and GIE are set;
• UCBxRXIFG and UCBxRXIE are reset by a system reset PUC signal or when SWRST = 1;
• UCxRXIFG is automatically reset when UCBxRXBUF is read.
15/01/2013
47
UBI
>> Contents93
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (9/11)
� I2C interrupts (continued):
� I2C transmit/receive interrupt operation:
UBI
>> Contents94
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (10/11)
� I2C interrupts (continued):
� I2C state change interrupt flags:
• Arbitration-lost, UCALIFG: Flag is set when two or more transmitters start a transmission simultaneously, or operates as master but is addressed as a slave by another master;
• Not-acknowledge interrupt, UCNACKIFG: Flag set when an acknowledge is expected but is not received;
• Start condition detected interrupt, UCSTTIFG: Flag set when the I2C module detects a START condition together with its own address while in slave mode;
• Stop condition detected interrupt, UCSTPIFG: Flag set when the I2C module detects a STOP condition while in slave mode.
15/01/2013
48
UBI
>> Contents95
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI operation: I2C mode (11/11)
� I2C interrupts (continued):
I2C TX interrupt: I2C RX interrupt:
UBI
>> Contents96
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes)(1/20)
� UCAxCTL0, USCI_Ax Control Register 0 (UART, SPI)
� UCBxCTL0, USCI_Bx Control Register 0 (SPI, I2C)Mode 7 6 5 4 3 2 1 0
UART UCPEN UCPAR UCMSB UC7BIT UCSPB UCMODEx UCSYNC=0
SPI UCCKPH UCCKPL UCMSB UC7BIT UCMST UCMODEx UCSYNC=1
I2C UCA10 UCSLA10 UCMM Unused UCMST UCMODEx=11 UCSYNC=1
Bit UART mode description SPI mode description I2C mode description
7 UCPEN Parity enable whenUCPEN = 1
UCCKPH Clock phase select:UCCKPH = 0 ⇒ Data is changed
on the 1st UCLK edge and captured on the next one.
UCCKPH = 1 ⇒ Data is captured on the 1st UCLK edge and changed on the next one.
UCA10 Own addressing mode select:UCA10= 0 ⇒ 7-bit addressUCA10= 1 ⇒ 10-bit address
6 UCPAR Parity select:UCPAR = 0 ⇒ Odd parityUCPAR = 1 ⇒ Even
parity
UCCKPL Clock polarity select.UCCKPL = 0 ⇒ Inactive state: low.UCCKPL = 1 ⇒ Inactive state:
high.
UCSLA10 Slave addressing mode select:
UCSLA10= 0 ⇒ 7-bit address
UCSLA10= 1 ⇒ 10-bit address
5 UCMSB MSB first select:UCMSB = 0 ⇒ LSB firstUCMSB = 1 ⇒ MSB first
UCMSB As UART mode UCMM Multi-master environment select:
UCMM= 0 ⇒ Single masterUCMM= 1 ⇒ Multi master
15/01/2013
49
UBI
>> Contents97
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes)(2/20)
� UCAxCTL0, USCI_Ax Control Register 0 (UART, SPI)
� UCBxCTL0, USCI_Bx Control Register 0 (SPI, I2C)Mode 7 6 5 4 3 2 1 0
UART UCPEN UCPAR UCMSB UC7BIT UCSPB UCMODEx UCSYNC=0
SPI UCCKPH UCCKPL UCMSB UC7BIT UCMST UCMODEx UCSYNC=1
I2C UCA10 UCSLA10 UCMM Unused UCMST UCMODEx=11 UCSYNC=1
Bit UART mode description SPI mode description I2C mode description
4 UC7BIT Character length:= 0 ⇒ 8-bit data= 1 ⇒ 7-bit data
UC7BIT As UART mode Unused
3 UCSPB Stop bit select:= 0 ⇒ One stop bit= 1 ⇒ Two stop bits
UCMST Master mode:= 0 ⇒ USART is slave= 1 ⇒ USART is master
UCMST Master mode select.= 0 ⇒ Slave mode= 1 ⇒ Master mode
2-1 UCMODEx USCI asynchronous mode:= 00 ⇒ UART= 01 ⇒ Idle-Line Multiproc.= 10 ⇒ Address-Bit Multiproc.= 11 ⇒ UART with ABR.
UCMODEx USCI synchronous mode:= 00 ⇒ 3-Pin SPI= 01 ⇒ 4-Pin SPI (slave enabled when UCxSTE=1)= 10 ⇒ 4-Pin SPI (slave enabled when UCxSTE=0)= 11 ⇒ I2C
UCMODEx=11 USCI Mode:= 00 ⇒ 3-Pin SPI= 01 ⇒ 4-Pin SPI (master/slave enabled if STE = 1)= 10 ⇒ 4-Pin SPI (master/slave enabled if STE = 0)= 11 ⇒ I2C
0 UCSYNC=0 Synchronous mode enable:= 0 ⇒ Asynchronous= 1 ⇒ Synchronous
UCSYNC=1 As UART mode UCSYNC=1 As UART mode
UBI
>> Contents98
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes)(3/20)
� UCAxCTL1, USCI_Ax Control Register 1 (UART, SPI)
� UCBxCTL1, USCI_Bx Control Register 1 (SPI, I2C)Mode 7 6 5 4 3 2 1 0
UART UCSSELx UCRXEIE UCBRKIE UCDORM UCTXADDR UCTXBRK UCSWRST
SPI UCSSELx Unused Unused Unused Unused Unused UCSWRST
I2C UCSSELx Unused UCTR UCTXNACK UCTXSTP UCTXSTT UCSWRST
Bit UART mode description SPI mode description I2C mode description
7-6 UCSSELx BRCLK source clock:= 00 ⇒ UCLK= 01 ⇒ ACLK= 10 ⇒ SMCLK= 11 ⇒ SMCLK
UCSSELx BRCLK source clock:= 00 ⇒ N/A= 01 ⇒ ACLK= 10 ⇒ SMCLK= 11 ⇒ SMCLK
UCSSELx BRCLK source clock:= 00 ⇒ UCLKI= 01 ⇒ ACLK= 10 ⇒ SMCLK= 11 ⇒ SMCLK
5 UCRXEIE Receive erroneous-character IE:= 0 ⇒ Rejected (UCAxRXIFG not set)= 1 ⇒ Received (UCAxRXIFG set)
Unused Unused Slave addressing mode select:UCSLA10= 0 ⇒ 7-bit addressUCSLA10= 1 ⇒ 10-bit address
4 UCBRKIE Receive break character IE:= 0 ⇒ Not set UCAxRXIFG.= 1 ⇒ Set UCAxRXIFG.
Unused UCTR Transmitter/Receiver select:= 0 ⇒ Receiver= 1 ⇒ Transmitter
15/01/2013
50
UBI
>> Contents99
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes)(4/20)
� UCAxCTL1, USCI_Ax Control Register 1 (UART, SPI)
� UCBxCTL1, USCI_Bx Control Register 1 (SPI, I2C)Mode 7 6 5 4 3 2 1 0
UART UCSSELx UCRXEIE UCBRKIE UCDORM UCTXADDR UCTXBRK UCSWRST
SPI UCSSELx Unused Unused Unused Unused Unused UCSWRST
I2C UCSSELx Unused UCTR UCTXNACK UCTXSTP UCTXSTT UCSWRST
Bit UART mode description SPI mode description
I2C mode description
3 UCDORM Dormant. Puts USCI into sleep mode:= 0 ⇒ Not dormant= 1 ⇒ Dormant
Unused UCTXNACK Transmit a NACK:= 0 ⇒ Acknowledge normally= 1 ⇒ Generate NACK
2 UCTXADDR Transmit address:= 0 ⇒ Next frame transmitted is data= 1 ⇒ Next frame transmitted is address
Unused UCTXSTP Transmit STOP condition in master mode:= 0 ⇒ No STOP generated= 1 ⇒ Generate STOP
1 UCTXBRK Transmit break:= 0 ⇒ Next frame transmitted is not a break= 1 ⇒ Next frame transmitted is a break or a break/synch
Unused UCTXSTT Transmit START condition in master mode:= 0 ⇒ No START generated= 1 ⇒ Generate START
0 UCSWRST Software reset enable=0 ⇒ Disabled. USCI reset released for operation1 ⇒ Enabled. USCI logic held in reset state
UCSWRST As UART mode UCSWRST As UART mode
UBI
>> Contents100
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (5/20)
� UCAxBR0, USCI_Ax Baud Rate Control Register 0 (UART, SPI)
� UCBxBR0, USCI_Bx Bit Rate Control Register 0 (SPI, I2C)
� UCAxBR1, USCI_Ax Baud Rate Control Register 1 (UART, SPI)
� UCBxBR1, USCI_Bx Bit Rate Control Register 1 (SPI, I2C)
Mode 7 6 5 4 3 2 1 0
UART / SPI / I2C UCBRx – low byte
Mode 7 6 5 4 3 2 1 0
UART / SPI / I2C UCBRx – high byte
Bit UART mode description SPI mode description I2C mode description
7-6 UCBRx Clock prescaler setting of the baud rate generator:Prescaler value (16-bit value) ={UCAxBR0+UCAxBR1x256}
UCBRx Bit clock prescaler setting:Prescaler value (16-bit value) ={UCAxBR0+UCAxBR1×256}
UCBRx As SPI mode
15/01/2013
51
UBI
>> Contents101
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (6/20)
� UCAxSTAT, USCI_Ax Status Register (UART, SPI)
� UCBxSTAT, USCI_Bx Status Register (SPI, I2C)Mode 7 6 5 4 3 2 1 0
UART UCLISTEN UCFE UCOE UCPE UCBRK UCRXERR UCADDR UCIDLE
UCBUSY
SPI UCLISTEN UCFE UCOE Unused Unused Unused Unused UCBUSY
I2C Unused UCSCLLOW UCGC UCBBUSY UCNACKIFG UCSTPIFG UCSTTIFG UCALIFG
Bit UART mode description SPI mode description I2C mode description
7 UCLISTEN Listen enable:= 0 ⇒ Disabled= 1 ⇒ UCAxTXD is internally fed back to receiver
UCLISTEN Listen enable:= 0 ⇒ Disabled= 1 ⇒ The transmitter output is internally fed back to receiver
Unused
6 UCFE Framing error flag:= 0 ⇒ No error= 1 ⇒ Character with low stop bit
UCFE Framing error flag:= 0 ⇒ No error= 1 ⇒ Bus conflict (4w master)
UCSCLLOW SCL low:= 0 ⇒ SCL is not held low= 1 ⇒ SCL is held low
5 UCOE Overrun error flag:= 0 ⇒ No error= 1 ⇒ Overrun error
UCOE As UART mode UCGC General call address received:= 0 ⇒ No general call address= 1 ⇒ General call address
UBI
>> Contents102
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (7/20)
� UCAxSTAT, USCI_Ax Status Register (UART, SPI)
� UCBxSTAT, USCI_Bx Status Register (SPI, I2C)Mode 7 6 5 4 3 2 1 0
UART UCLISTEN UCFE UCOE UCPE UCBRK UCRXERR UCADDR UCIDLE
UCBUSY
SPI UCLISTEN UCFE UCOE Unused Unused Unused Unused UCBUSY
I2C Unused UCSCLLOW UCGC UCBBUSY UCNACKIFG UCSTPIFG UCSTTIFG UCALIFG
Bit UART mode description SPI mode description I2C mode description
4 UCPE Parity error flag:= 0 ⇒ No error= 1 ⇒ Character with parity error
Unused UCBBUSY Bus busy:= 0 ⇒ Bus inactive= 1 ⇒ Bus busy
3 UCBRK Break detect flag:= 0 ⇒ No break condition= 1 ⇒ Break condition occurred
Unused UCNACKIFG NACK received interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
2 UCRXERR Receive error flag.= 0 ⇒ No receive errors detected= 1 ⇒ Receive error detected
Unused UCSTPIFG Stop condition interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
1 UCADDRUCIDLE
Address-bit multiproc. mode:= 0 ⇒ Received character is data= 1 ⇒ Received character is an addressIdle-line multiproc. mode:= 0 ⇒ No idle line detected= 1 ⇒ Idle line detected
Unused UCSTTIFG Start condition interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
0 UCBUSY USCI busy:= 0 ⇒ USCI inactive= 1 ⇒ USCI transmit/receive
UCBUSY UCALIFG Arbitration lost interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
15/01/2013
52
UBI
>> Contents103
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (8/20)
� UCAxRXBUF, USCI_Ax Receive Buffer Register (UART, SPI)
� UCBxRXBUF, USCI_Bx Receive Buffer Register (SPI, I2C)
Mode 7 6 5 4 3 2 1 0
UART / SPI / I2C UCRXBUFx
Bit UART mode description
SPI mode description
I2C mode description
7-0 UCRXBUFx The receive-data buffer is user accessible and contains the last received character from the receive shift register.Reading UCxRXBUF resets receive-error bits, UCADDR/UCIDLE bit and UCAxRXIFG.In 7-bit data mode, UCAxRXBUF is LSB justified and the MSB is always cleared.
UCRXBUFx As UART modeReading UCxRXBUF resets thereceive-error bits, and UCxRXIFG
UCRXBUFx As SPI mode
UBI
>> Contents104
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (9/20)
� UCAxTXBUF, USCI_Ax Transmit Buffer Register (UART, SPI)
� UCBxTXBUF, USCI_Bx Transmit Buffer Register (SPI, I2C)
Mode 7 6 5 4 3 2 1 0
UART / SPI / I2C UCTXBUFx
Bit UART mode description
SPI mode description
I2C mode description
7-0 UCTXBUFx The transmit data buffer is user accessible and holds the data waiting to be moved into the transmit shift register and transmitted on UCAxTXD.Writing to the transmit data buffer clears UCAxTXIFG.
UCTXBUFx The transmit data buffer is user accessible and holds the data waiting to be moved into the transmit shift register and transmitted.Writing to the transmit data buffer clears UCxTXIFG.
UCTXBUFx As SPI mode
15/01/2013
53
UBI
>> Contents105
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (10/20)
� IE2, Interrupt Enable Register 2 (UART, SPI, I2C)Mode 7 6 5 4 3 2 1 0
UART UCA0TXIE UCA0RXIE
SPI UCB0TXIE UCB0RXIE UCA0TXIE UCA0RXIE
I2C UCB0TXIE UCB0RXIE
Bit UART mode description
SPI mode description
I2C mode description
3 UCB0TXIE USCI_B0 transmit interrupt enable:= 0 ⇒ Disabled= 1 ⇒ Enabled
UCB0TXIE As SPI mode
2 UCB0RXIE USCI_B0 receive interrupt enable:= 0 ⇒ Disabled= 1 ⇒ Enabled
UCB0RXIE As SPI mode
1 UCA0TXIE USCI_A0 transmit interrupt enable:= 0 ⇒ Disabled= 1 ⇒ Enabled
UCA0TXIE As UART mode
0 UCA0RXIE USCI_A0 receive interrupt enable:= 0 ⇒ Disabled= 1 ⇒ Enabled
UCA0RXIE As UART mode
UBI
>> Contents106
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (11/20)
� IFG2, Interrupt Flag Register 2 (UART, SPI, I2C)Mode 7 6 5 4 3 2 1 0
UART UCA0TXIFG UCA0RXIFG
SPI UCB0TXIFG UCB0RXIFG UCA0TXIFG UCA0RXIFG
I2C UCB0TXIFG UCB0RXIFG
Bit UART mode description SPI mode description I2C mode description
3 UCB0TXIFG USCI_B0 transmit interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
UCB0TXIFG As SPI mode
2 UCB0RXIFG USCI_B0 receive interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
UCB0RXIFG As SPI mode
1 UCA0TXIFG USCI_A0 transmit interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
UCA0TXIFG As UART mode
0 UCA0RXIFG USCI_A0 receive interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
UCA0RXIFG As UART mode
15/01/2013
54
UBI
>> Contents107
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (12/20)
� UC1IE, USCI_A1 Interrupt Enable Register (UART, SPI)
� UC1IE, USCI_B1 Interrupt Enable Register (SPI, I2C)
Mode 7 6 5 4 3 2 1 0
UART Unused Unused Unused Unused UCA1TXIE UCA1RXIE
SPI Unused Unused Unused Unused UCB1TXIE UCB1RXIE UCA1TXIE UCA1RXIE
I2C Unused Unused Unused Unused UCB1TXIE UCB1RXIE
Bit UART mode description SPI mode description I2C mode description
3 UCB1TXIE USCI_B1 transmit interrupt enable:UTXIE1 = 0 ⇒ DisabledUTXIE1 = 1 ⇒ Enabled
UCB1TXIE As SPI mode
2 UCB1RXIE USCI_B1 receive interrupt enable:URXIE1 = 0 ⇒ DisabledURXIE1 = 1 ⇒ Enabled
UCB1RXIE As SPI mode
1 UCA1TXIE USCI_A1 transmit interrupt enable:UTXIE1 = 0 ⇒ DisabledUTXIE1 = 1 ⇒ Enabled
UCA1TXIE As UART mode
0 UCA1RXIE USCI_A1 receive interrupt enable:URXIE1 = 0 ⇒ DisabledURXIE1 = 1 ⇒ Enabled
UCA1RXIE As UART mode
UBI
>> Contents108
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (13/20)
� UC1IFG, USCI_A1 Interrupt Flag Register (UART, SPI)
� UC1IFG, USCI_B1 Interrupt Flag Register (SPI, I2C)
Mode 7 6 5 4 3 2 1 0
UART UCA1TXIFG UCA1RXIFG
SPI UCB1TXIFG UCB1RXIFG UCA1TXIFG UCA1RXIFG
I2C UCB1TXIFG UCB1RXIFG
Bit UART mode description SPI mode description I2C mode description
3 UCB1TXIFG USCI_B1 transmit interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
UCB1TXIFG As SPI mode
2 UCB1RXIFG USCI_B1 receive interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
UCB1RXIFG As SPI mode
1 UCA1TXIFG USCI_A1 transmit interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
UCA1TXIFG As UART mode
0 UCA1RXIFG USCI_A1 receive interrupt flag:= 0 ⇒ No interrupt pending= 1 ⇒ Interrupt pending
UCA1RXIFG As UART mode
15/01/2013
55
UBI
>> Contents109
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (14/20)
� UCAxMCTL, USCI_Ax Modulation Control Register (UART)
7 6 5 4 3 2 1 0
UCBRFx UCBRSx UCOS16
Bit UART mode description
7-4 UCBRFx First modulation pattern for BITCLK16 when UCOS16 = 1(See Table 19-3 of the MSP430x4xx User’s Guide)
3-1 UCBRSx Second modulation pattern for BITCLK(See Table 19-2 of the MSP430x4xx User’s Guide)
0 UCOS16 Oversampling mode enabled when UCOS16 = 1
UBI
>> Contents110
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (15/20)
� UCAxIRTCTL, USCI_Ax IrDA Transmit Control Register (UART)
7 6 5 4 3 2 1 0
UCIRTXPLx UCIRTXCLK UCIREN
Bit UART mode description
7-2 UCIRTXPLx Transmit pulse length:tPULSE = (UCIRTXPLx + 1) / (2 x fIRTXCLK)
1 UCIRTXCLK IrDA transmit pulse clock select:UCIRTXCLK = 0 ⇒ BRCLKUCIRTXCLK = 1 ⇒ BITCLK16, when UCOS16 = 1
⇒ BRCLK, otherwise
0 UCIREN IrDA encoder/decoder enable:UCIREN = 0 ⇒ IrDA encoder/decoder disabledUCIREN = 1 ⇒ IrDA encoder/decoder enabled
15/01/2013
56
UBI
>> Contents111
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (16/20)
� UCAxIRRCTL, USCI_Ax IrDA Receive Control Register (UART)7 6 5 4 3 2 1 0
UCIRRXFLx UCIRRXPL UCIRRXFE
Bit UART mode description
7-2 UCIRRXFLx Receive filter length (minimum pulse length):tMIN = (UCIRRXFLx + 4) / (2 × fIRTXCLK)
1 UCIRRXPL IrDA receive input UCAxRXD polarity. When a light pulse is seen:UCIRRXPL = 0 ⇒ IrDA transceiver delivers a high pulse UCIRRXPL = 1 ⇒ IrDA transceiver delivers a low pulse
0 UCIRRXFE IrDA receive filter enabled:UCIRRXFE = 0 ⇒ DisabledUCIRRXFE = 1 ⇒ Enabled
UBI
>> Contents112
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (17/20)
� UCAxABCTL, USCI_Ax Auto Baud Rate Control Register (UART)
7 6 5 4 3 2 1 0
Reserved UCDELIMx UCSTOE UCBTOE Reserved UCABDEN
Bit UART mode description
5-4 UCDELIMx Break/synch delimiter length:UCDELIM1 UCDELIM0 = 00 ⇒ 1 bit timeUCDELIM1 UCDELIM0 = 01 ⇒ 2 bit timesUCDELIM1 UCDELIM0 = 10 ⇒ 3 bit timesUCDELIM1 UCDELIM0 = 11 ⇒ 4 bit times
3 UCSTOE Synch field time out error:UCSTOE = 0 ⇒ No errorUCSTOE = 1 ⇒ Length of synch field exceeded measurable time
2 UCBTOE Break time out error:UCBTOE = 0 ⇒ No errorUCBTOE = 1 ⇒ Length of break field exceeded 22 bit times.
0 UCABDEN Automatic baud rate detect enable:UCABDEN = 0 ⇒ Baud rate detection disabledUCABDEN = 1 ⇒ Baud rate detection enabled
15/01/2013
57
UBI
>> Contents113
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (18/20)
� UCBxI2COA, USCIBx I2C Own Address Register (I2C)15 14 13 12 11 10 9 8
UCGCEN 0 0 0 0 0 I2COAx
7 6 5 4 3 2 1 0
I2COAx
Bit UART mode description
15 UCGCEN General call response enable:UCGCEN = 0 ⇒ Do not respond to a general callUCGCEN = 1 ⇒ Respond to a general call
9-0 I2COAx I2C own address (local address of the USCI_Bx I2C controller)⇒ Right-justified address⇒ 7-bit address ⇒ Bit 6 is the MSB, Bits 9-7 are ignored.⇒ 10-bit address ⇒ Bit 9 is the MSB.
UBI
>> Contents114
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (19/20)
� UCBxI2CSA, USCI_Bx I2C Slave Address Register (I2C)15 14 13 12 11 10 9 8
0 0 0 0 0 0 I2CSAx
7 6 5 4 3 2 1 0
I2CSAx
Bit UART mode description
9-0 I2CSAx I2C slave address (slave address of the external device to be addressed by the USCI_Bx module)⇒ Only used in master mode⇒ Right-justified address⇒ 7-bit address ⇒ Bit 6 is the MSB, Bits 9-7 are ignored.⇒ 10-bit address ⇒ Bit 9 is the MSB.
15/01/2013
58
UBI
>> Contents115
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USCI registers (UART, SPI and I2C modes) (20/20)
� UCBxI2CIE, USCI_Bx I2C Interrupt Enable Register (I2C)
7 6 5 4 3 2 1 0
Reserved UCNACKIE UCSTPIE UCSTTIE UCALIE
Bit UART mode description
3 UCNACKIE Not-acknowledge interrupt enable:UCNACKIE = 0 ⇒ Interrupt disabledUCNACKIE = 1 ⇒ Interrupt enabled
2UCSTPIE
Stop condition interrupt enable:UCSTPIE = 0 ⇒ Interrupt disabledUCSTPIE = 1 ⇒ Interrupt enabled
1UCSTTIE
Start condition interrupt enable:UCSTTIE = 0 ⇒ Interrupt disabledUCSTTIE = 1 ⇒ Interrupt enabled
0UCALIE
Arbitration lost interrupt enable:UCALIE = 0 ⇒ Interrupt disabledUCALIE = 1 ⇒ Interrupt enabled
UBI
>> Contents116
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (1/6)
� 1. The USCI module has:
(a) One module;
(b) Two modules;
(c) Three modules;
(d) None.
� 2. The USCI module in UART mode supports:
(a) LIN;
(b) IrDA;
(c) All of above;
(d) None of above.
15/01/2013
59
UBI
>> Contents117
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (2/6)
� 3. The UCMSB bit controls:
(a) The direction of the data transfer;
(b) Selects LSB or MSB first;
(c) All of above;
(d) None of above.
� 4. The automatic baud rate detection uses a “break” which is:
(a) Detected when 11 or more continuous “0”s are received;
(b) Detected when 4 or more continuous “0”s are received;
(c) Detected when 8 or more continuous “0”s are received;
(d) None.
UBI
>> Contents118
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (3/6)
� 5. The automatic baud rate detection uses a synch field which is represented by:
(a) Data 022h inside a byte field;
(b) Data 055h inside a byte field;
(c) Data 044h inside a byte field;
(d) None.
� 6. The USCI module in UART mode for IrDA decoding detects:
(a) Low pulse;
(b) High pulse;
(c) All of above;
(d) None.
15/01/2013
60
UBI
>> Contents119
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (4/6)
� 7. The baud rate can be generated using:
(a) A low frequency;
(b) Oversampling;
(c) All of above;
(d) None of above.
� 8. In USCI I2C communication, the ACK bit is sent from the receiver after:
(a) Each bit on the 9th SCL clock;
(b) Each byte on the 2th SCL clock;
(c) Each bit on the 2th SCL clock;
(d) Each byte on the 9th SCL clock.
UBI
>> Contents120
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (5/6)
� 9. The operating modes provided by the I2C mode are:
(a) Master transmitter and Slave receiver;
(b) Slave transmitter and Master receiver;
(c) All of above;
(d) None of above.
� 10. The I2C state change interrupt flags are:
(a) Arbitration-lost and Not-acknowledge;
(b) Start and stop conditions;
(c) All of above;
(d) None of above.
15/01/2013
61
UBI
>> Contents121
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (6/6)
� Answers:
1. (b) Two modules.
2. (c) All of above.
3. (c) All of above.
4. (a) Detected when 11 or more continuous “0”s are received.
5. (b) Data 055h inside a byte field.
6. (c) All of above.
7. (c) All of above.
8. (d) Each byte on the 9th SCL clock.
9. (c) All of above.
10. (c) All of above.
UBI
>> Contents
Chapter 7Communicaciones
USI Module
MSP430 Teaching Materials
Texas Instruments IncorporatedUniversity of Beira Interior (PT)
Pedro Dinis Gaspar, António Espírito Santo, Bruno Ribeiro, Humberto SantosUniversity of Beira Interior, Electromechanical Engineering Department
www.msp430.ubi.pt
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
15/01/2013
62
UBI
>> Contents123
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Contents
� MSP430 communications interfaces
� USI module introduction
� USI operation: SPI mode
� USI operation: I2C mode
� USI registers (SPI and I2C modes)
� Lab10b: Echo test using SPI
� Lab10c: Echo test using I2C
� Quiz
UBI
>> Contents124
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI module introduction (1/2)
� The USI (Universal Serial Interface) module supports basic SPI and I2C synchronous serial communications;
� It is available in the MSP430x20xx family of devices;
� The USI module supports:
� SPI or I2C modes;
� Interrupt driven;
� Reduces CPU load;
� Flexible clock source selection.
15/01/2013
63
UBI
>> Contents125
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI module introduction (2/2)
� USI block diagram:
� SPI mode:
• Programmable data length (8/16-bit shift register);
• MSB/LSB first.
� I2C mode:
• START/STOP detection;
• Arbitration lost detection.
� Interrupt driven;
� Reduces CPU load;
� Flexible clock source.
UBI
>> Contents126
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: SPI and I2C modes (1/5)
� Shift register and bit counter that include logic to support SPI and I2C communication;
� USISR shift register (up to 16 bits supported):
� Directly accessible by software;
� Contains the data to be transmitted/received (simultaneously);
� MSB or LSB first.
� Bit counter:
� Controls the number of bits transmitted/received;
� Counts the number of sampled bits;
� Sets USIIFG when the USICNTx = 0 (decrementing or writing zero to USICNTx bits);
� Writing USICNTx > 0 automatically clears USIIFG when USIIFGCC = 0 (automatically stops clocking after last bit).
15/01/2013
64
UBI
>> Contents127
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: SPI and I2C modes (2/5)
� USI initialization:
� Reset USISWRST;
� Set USIPEx bits (USI function for the pin and maintains the PxIN and PxIFG functions for the pin):
• Port input levels can be read via the PxIN register by software;
• Incoming data stream can generate port interrupts on data transitions.
UBI
>> Contents128
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: SPI and I2C modes (3/5)
� Recommended USI initialization process:
� Set the USIPEx bits in the USI control register (USI function for the pin and set up the PxIN and PxIFG functions for the pin as well);
� Set the direction of the RX and TX shift register (MSB or LSB first) by USILSB bit;
� Select the mode (master or slave) by USIMTS bit;
� Enable or disable output data by USIOE bit;
� Enable USI interrupts by setting USIIE bit;
� Set up USI clock by configuring the USICKCTL control register;
� Enable USI by setting USISWRST bit;
� Read port input levels via the PxIN register by software;
� Incoming data stream will generate port interrupts on data transitions.
15/01/2013
65
UBI
>> Contents129
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: SPI and I2C modes (4/5)
� USI clock generation:
� Clock selection multiplexer:
• Internal clocks ACLK or SMCLK;
• External clock SCLK;
• USISWCLK (software clock input bit);
• Timer_A CAP/COM outputs.
� Configurable divider;
� Auto-stop on interrupt: USIIFG;
� Selectable phase and polarity.
UBI
>> Contents130
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: SPI and I2C modes (5/5)
� USICKPL: Selects the inactive level of the SPI clock (data latching on rising or falling edge);
� USICKPH: Selects the clock edge on which SDO is updated and SDI is sampled (idle high or low support).
� USIIFG automatically cleared and set by USICNTx;
� Clock stop on IFG: USIIFG and USISTTIFG.
15/01/2013
66
UBI
>> Contents131
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: SPI mode (1/2)
� Configure SPI mode:
� SPI master:
• USIMST = 1;
• USII2C = 0;
• Select clock source;
• SCLK -> output.
� SPI slave:
• USIMST = 0;
• USII2C = 0;
• SCLK -> input;
• Receives the clock externally from the master.
� USIPEx bits enable data and clock pins;
� Port logic functions, including interrupts as normal;
� Data output latched on shift clock.
UBI
>> Contents132
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: SPI mode (2/2)
� SPI interrupts:
� One interrupt vector associated with the USI module;
� One interrupt flag, USIIFG:
• Set when bit counter counts to zero;
• Generates an interrupt request when USIIE = 1;
• Cleared when USICNTx > 0 (USIIFGCC = 0), or directly by software;
• Stops clock when set.
15/01/2013
67
UBI
>> Contents133
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (1/10)
� Configure USI module in I2C mode:
� USII2C =1;
� USICKPL = 1;
� USICKPH = 0;
� I2C data compatibility:
� USILSB = 0;
� USI16B = 0;
� Enable SCL and SDA
port functions:
� Set USIPE6 and USIPE7.
UBI
>> Contents134
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (2/10)
� I2C master:
� USIMST = 1 and USII2C = 1;
� Select clock source (output to SCL line while USIIFG = 0).
� I2C slave:
� USIMST = 0;
� SCL is held low if USIIFG=1, USISTTIFG=1 or if USICNTx=0.
15/01/2013
68
UBI
>> Contents135
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (3/10)
� I2C transmitter:
� Data value is first loaded into USISRL;
� USIOE= 1: Enable output and start transmission (writes 8 into USICNTx);
� Send Start (or repeated Start);
� Define address and set R/W;
� Slave ACK: (Data TX/RX + ACK for N bytes);
� SCL is generated in master mode or released from being held low in slave mode;
� USIIFG is set after the transmission of all 8 bits (stops clock signal on SCL in master mode or held low at the next low phase in slave mode);
� Stop (or repeated Start).
UBI
>> Contents136
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (4/10)
� I2C receiver:
� Clear USIOE (disable output);
� Enable reception by writing 8 into USICNTx (USIIFG = 0);
� SCL is generated in master mode or released from being held low in slave mode;
� USIIFG is set after 8 clocks (stops the clock signal on SCL in master mode or holds SCL low at the next low phase in slave mode).
15/01/2013
69
UBI
>> Contents137
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (5/10)
� SDA configuration:
� Direction;
� Used for TX/RX, ACK/NACK handling and START/STOP generation;
� USIGE: Output latch control;
� USIOE: Data output enable.
UBI
>> Contents138
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (6/10)
� START condition:
� (high-to-low transition on SDA while SCL is high);
� Clear MSB of the shift register;
� USISTTIFG set on start (Sources USI interrupt).
15/01/2013
70
UBI
>> Contents139
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (7/10)
� STOP condition:
� (low-to-high transition on SDA while SCL is high):
� Clear the MSB in the shift register and loads 1 into USICNTx (finishes the acknowledgment bit and pulls SDA low);
� USISTP set on stop (CPU-accessible flag).
UBI
>> Contents140
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (8/10)
� Receiver ACK/NACK generation:
� After address/data reception;
� SDA = output;
� Output 1 data bit: 0 = ACK, 1 = NACK.
� Transmitter ACK/NACK Detection:
� After address/data transmission;
� SDA = input;
� Receive 1 data bit: 0 = ACK, 1 = NACK.
� Arbitration procedure (in multi-master I2C systems);
15/01/2013
71
UBI
>> Contents141
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (9/10)
� I2C Interrupts:
� One interrupt vector associated with the USI;
� Two interrupt flags, USIIFG and USISTTIFG;
� Each interrupt flag has its own interrupt enable bit, USIIE and USISTTIE;
� When an interrupt is enabled and the GIE bit is set, a set interrupt flag will generate an interrupt request;
� USIIFG is set (USICNTx = 0);
� USISTTIFG is set (START condition detection).
UBI
>> Contents142
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI operation: I2C mode (10/10)
� Example:
� Procedure for I2C communication between a Master TX and a Slave RX.
Master TX Slave RX
1: Send Start, Address and R/W bit 1: Detect Start, receive address and R/W
2: Receive (N)ACK 2: Transmit (N)ACK
3: Test (N)ACK and handle TX data 3: Data RX
4: Receive (N)ACK 4: Transmit (N)ACK
5: Test (N)ACK and prepare Stop 5: Reset for next Start
6: Send Stop
15/01/2013
72
UBI
>> Contents143
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI registers (SPI and I2C modes) (1/8)
� USICTL0, USI Control Register 07 6 5 4 3 2 1 0
USIPE7 USIPE6 USIPE5 USILSB USIMST USIGE USIOE USIWRST
Bit Description
7 USIPE7 USI SDI/SDA port enable: ⇒ SPI mode ⇒ Input ⇒ I2C mode ⇒ Input or open drain output
USIPE7 = 0 ⇒ USI function disabled USIPE7 = 1 ⇒ USI function enabled
6 USIPE6 USI SDO/SCL port enable: ⇒ SPI mode ⇒ Output
⇒ I2C mode ⇒ Input or open drain output USIPE6 = 0 ⇒ USI function disabled USIPE6 = 1 ⇒ USI function enabled
5 USIPE5 USI SCLK port enable: ⇒ SPI slave mode ⇒ Input ⇒ SPI master mode ⇒ Output ⇒ I2C mode ⇒ Input
USIPE5 = 0 ⇒ USI function disabled USIPE5 = 1 ⇒ USI function enabled
UBI
>> Contents144
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI registers (SPI and I2C modes) (2/8)
� USICTL0, USI Control Register 0 (continued)7 6 5 4 3 2 1 0
USIPE7 USIPE6 USIPE5 USILSB USIMST USIGE USIOE USIWRST
4 USILSB LSB first select (direction of the receive and transmit shift register): USILSB = 0 ⇒ MSB first USILSB = 1 ⇒ LSB first
3 USIMST Master select: USIMST = 0 ⇒ Slave mode USIMST = 1 ⇒ Master mode
2 USIGE Output latch control: USIGE = 0 ⇒ Output latch enable depends on shift clock USIGE = 1 ⇒ Output latch always enabled and transparent
1 USIOE Data output enable:
USIOE = 0 ⇒ Output disabled USIOE = 1 ⇒ Output enabled
0 USIWRST USI software reset:
USIWRST = 0 ⇒ USI released for operation USIWRST = 1 ⇒ USI logic held in reset state
15/01/2013
73
UBI
>> Contents145
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI registers (SPI and I2C modes) (3/8)
� USICTL1, USI Control Register 17 6 5 4 3 2 1 0
USICKPH USII2C USISTTIE USIIE USIAL USISTP USISTTIFG USIIFG
Bit Description
7 USICKPH Clock phase select: USICKPH = 0 ⇒ Data is changed on the first SCLK edge and captured on the following edge
USICKPH = 1 ⇒ Data is captured on the first SCLK edge and changed on the following edge
6 USII2C I2C mode enable: USII2C = 0 ⇒ I2C mode disabled USII2C = 1 ⇒ I2C mode enabled
5 USISTTIE START condition interrupt-enable: USISTTIE = 0 ⇒ Interrupt on START condition disabled USISTTIE = 1 ⇒ Interrupt on START condition enabled
4 USIIE USI counter interrupt enable: USIIE = 0 ⇒ Interrupt disabled USIIE = 1 ⇒ Interrupt enabled
UBI
>> Contents146
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI registers (SPI and I2C modes) (4/8)
� USICTL1, USI Control Register 1 (continued)7 6 5 4 3 2 1 0
USICKPH USII2C USISTTIE USIIE USIAL USISTP USISTTIFG USIIFG
3 USIAL Arbitration lost: USIAL = 0 ⇒ No arbitration lost condition USIAL = 1 ⇒ Arbitration lost
2 USISTP STOP condition received:
USISTP = 0 ⇒ No STOP condition received USISTP = 1 ⇒ STOP condition received
1 USISTTIFG START condition interrupt flag:
USISTTIFG = 0 ⇒ No interrupt pending USISTTIFG = 1 ⇒ Interrupt pending
0 USIIFG USI counter interrupt flag: USIIFG = 0 ⇒ No interrupt pending
USIIFG = 1 ⇒ Interrupt pending
15/01/2013
74
UBI
>> Contents147
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI registers (SPI and I2C modes) (5/8)
� USICKCTL, USI Clock Control Register7 6 5 4 3 2 1 0
USIDIVx USISSELx USICKPL USISWCLK
Bit Description
7-5 USIDIVx Clock divider select: USIDIV2 USIDIV1 USIDIV0 = 000 ⇒ Divide by 1 USIDIV2 USIDIV1 USIDIV0 = 001 ⇒ Divide by 2
USIDIV2 USIDIV1 USIDIV0 = 010 ⇒ Divide by 4 USIDIV2 USIDIV1 USIDIV0 = 011 ⇒ Divide by 8 USIDIV2 USIDIV1 USIDIV0 = 100 ⇒ Divide by 16
USIDIV2 USIDIV1 USIDIV0 = 101 ⇒ Divide by 32 USIDIV2 USIDIV1 USIDIV0 = 110 ⇒ Divide by 64 USIDIV2 USIDIV1 USIDIV0 = 111 ⇒ Divide by 128
4-2 USISSELx Clock source select. Not used in slave mode.
USISSEL2 USISSEL1 USISSEL0 = 000 ⇒ SCLK (1) USISSEL2 USISSEL1 USISSEL0 = 001 ⇒ ACLK USISSEL2 USISSEL1 USISSEL0 = 010 ⇒ SMCLK
USISSEL2 USISSEL1 USISSEL0 = 011 ⇒ SMCLK USISSEL2 USISSEL1 USISSEL0 = 100 ⇒ USISWCLK bit USISSEL2 USISSEL1 USISSEL0 = 101 ⇒ TACCR0
USISSEL2 USISSEL1 USISSEL0 = 110 ⇒ TACCR1 USISSEL2 USISSEL1 USISSEL0 = 111 ⇒ TACCR2 (2) (1) Not used in SPI mode (2) Reserved on MSP430F20xx devices
UBI
>> Contents148
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI registers (SPI and I2C modes) (6/8)
� USICKCTL, USI Clock Control Register (continued)7 6 5 4 3 2 1 0
USIDIVx USISSELx USICKPL USISWCLK
1 USICKPL Clock polarity select: USICKPL = 0 ⇒ Inactive state is low USICKPL = 1 ⇒ Inactive state is high
0 USISWCLK Software clock:
USISWCLK = 0 ⇒ Input clock is low USISWCLK = 1 ⇒ Input clock is high
15/01/2013
75
UBI
>> Contents149
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI registers (SPI and I2C modes) (7/8)
� USICNT, USI Bit Counter Register7 6 5 4 3 2 1 0
USISCLREL USI16B USIIFGCC USICNTx
Bit Description
7 USISCLREL SCL line release from low to idle: USISCLREL = 0 ⇒ SCL line is held low if USIIFG is set USISCLREL = 1 ⇒ SCL line is released
6 USI16B 16-bit shift register enable:
USI16B = 0 ⇒ 8-bit shift register mode. (Uses USISRL low byte) USI16B = 1 ⇒ 16-bit shift register mode (Uses both USISRx bytes)
5 USIIFGCC USI interrupt flag clear control: USIIFGCC = 0 ⇒ USIIFG automatically cleared on USICNTx update
USIIFGCC = 1 ⇒ USIIFG is not cleared automatically 4-0 USICNTx USI bit count (Number of bits to be received or transmitted)
UBI
>> Contents150
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
USI registers (SPI and I2C modes) (8/8)
� USISRL, USI Low Byte Shift Register
� USISRH, USI High Byte Shift Register
7 6 5 4 3 2 1 0
USISRLx
Bit Description
7-0 USISRLx Contents of the USI low byte shift register
7 6 5 4 3 2 1 0
USISRHx
Bit Description
7-0 USISRHx Contents of the USI high byte shift register
15/01/2013
76
UBI
>> Contents151
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (1/17)
� Project files:
� C source files: Chapter 14 > Lab10 > Lab10b1_student.
Chapter 14 > Lab10 > Lab10b2_student.c
� Solution files: Chapter 14 > Lab10 > Lab10b1_solution.c
Chapter 14 > Lab10 > Lab10b2_solution.c
� Overview:
� This laboratory explores the USCI and USI communication interfaces in SPI mode;
� The MSP430 devices supported by the Experimenter’s board will exchange messages between themselves;
UBI
>> Contents152
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (2/17)
� Overview (continued):
� MSP430FG4618: Master reads the current state of the slave, and drives it to the new desired state;
� MSP430F2013: Slave commanded by the Master.
� A. Resources:
� USCI module: MSP430FG4618;
� USI module: MSP430F2013;
� Both units operate in SPI mode;
� Basic Timer1 of the master device is programmed to switch the status of the slave device once every 2 seconds;
� The slave is notified of the arrival of information through the end of counting interrupt of the USI module.
15/01/2013
77
UBI
>> Contents153
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (3/17)
� A. Resources (continued):
� The resources used are:
• USCI module;
• USI module;
• Basic Timer1;
• Interrupts;
• I/O ports.
UBI
>> Contents154
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (4/17)
� B. Software application organization:
Basic Timer
ISR
Main
Master Task
USCI
SPI
P3.0
Basic
Timer
RX
TX
2s
USI
ISR
Main
Slave Task
USI
SPI
P1.4
RX
TX
SOMI
SIMO
SCLK
Slave Status
SLAVEMASTER
LED3
15/01/2013
78
UBI
>> Contents155
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (5/17)
� B. Software application organization:
� The master unit is composed of two software modules:
• The "Main master task" module contains the operational algorithm of the master unit;
• The "ISR Basic Timer" module wakes the "Main master task" with a rate of once every 2 seconds.
� Similarly, the slave unit is composed of two modules:
• The "Main slave task" module contains the operational algorithm of the slave unit;
• The "USI ISR" module reads the data received, prepares the USI module for reception of a new command and wakes the "Main slave task" to execute the algorithm associated with the reception of the new command.
UBI
>> Contents156
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (6/17)
� C. Configuration:
� Configure the control registers USCI_B (master):
• The SPI connection will operate as follows:
– Clock phase -> Data bits are sent on the first UCLK edge and captured on the following edge;
– Clock polarity -> the inactive state is low;
– MSB first;
– 8-bit data;
– Master mode;
– 3-Pin SPI;
– Source clock -> SMCLK.
15/01/2013
79
UBI
>> Contents157
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (7/17)
� C. Configuration (continued):
� Configure the control registers USCI_B (master):
• Configure the following control registers based on these characteristics:
UCB0CTL0 = _______________;
UCB0CTL1 = _______________;
UBI
>> Contents158
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (8/17)
� C. Configuration (continued):
� Data rate USCI_B (master):
• The system clock is configured to operate with a frequency of ~ 1048 kHz from the DCO;
• This frequency will be the working base of the USCI module;
• The connection operates at a clock frequency of ~ 500 kHz. Configure the following registers:
UCB0BR0= _______________;
UCB0BR1= _______________;
15/01/2013
80
UBI
>> Contents159
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (9/17)
� C. Configuration (continued):
� Ports configuration USCI_B (master):
• In order to set the external interfaces of the USCI module, it is necessary to configure the I/O ports;
• Select the USCI peripheral in SPI mode following the connections provided at the Experimenter’s board:
P3SEL = __________________;
UBI
>> Contents160
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (10/17)
� C. Configuration (continued):
� Configure the control registers USI (slave):
• The SPI connection will operate in the following mode:
– MSB first;
– 8-bit data;
– Slave mode;
– Clock phase -> Data bits are sent on the first SCLK edge and captured on the following edge;
– USI counter interrupt enable.
15/01/2013
81
UBI
>> Contents161
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (11/17)
� C. Configuration (continued):
� Configure the control registers USI (slave):
• Configure the following control registers based on these characteristics:
USICTL0 = _______________;
USICTL1 = _______________;
UBI
>> Contents162
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (12/17)
� D. Analysis of operation:
� Once the USCI module is configured in accordance with the previous steps, to initiate the experiment, complete the files Lab10b1_student.c (master – MSP430FG4618) and Lab10b2_student.c (slave – MSP430F2013), compile them and run them on the Experimenter’s board;
� The finished solution can be found in the files Lab10b1_solution.c and Lab10b2_soluction.c.
� For this laboratory, the following jumper settings are required:
• PWR1/2, BATT, LCL1/2, JP2;
• SPI: H1- 1&2, 3&4, 5&6, 7&8.
15/01/2013
82
UBI
>> Contents163
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (13/17)
� D. Analysis of operation:
� Verification:
• Once the program code is running in the two microcontrollers, monitor LED3 of the Experimenter’s board. It will blink at a rate of 4 flashes per second.
UBI
>> Contents164
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (14/17)
� Control registers USCI_B (master):UCB0CTL0 = 0x29;
//UCB0CTL0 = UCCKPH|UCCKPL|UCMSB|UC7BIT|UCMST|UCMODEx|UCSYNC
//UCCKPH (Clock phase) = 0b -> Data is changed on the
// first UCLK edge and captured on the following edge.
//UCCKPL (Clock polarity) = 0b -> Inactive state is low
//UCMSB (MSB first select) = 1b -> MSB first
//UC7BIT (Character length) = 0b -> 8-bit data
//UCMST (Master mode) = 1b -> Master mode
//UCMODEx (USCI mode) = 00b -> 3-Pin SPI
//UCSYNC (Synch. mode enable) = 1b -> Synchronous mode
MSP-EXP430FG4618 (master)
SOLUTION
Using USCI module in SPI mode included in the FG4618 (configured as master) of theExperimenter’s board, establish a connection to the F2013 by its USI module in SPImode. The data exchanged is displayed by the LED blinking.
15/01/2013
83
UBI
>> Contents165
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (15/17)
� Control registers USCI_B (master):UCB0CTL1 = 0x81;
//UCB0CTL1 = UCSSELx | Unused |UCSWRST|
//UCSSELx (USCI clock source select)= 10b -> SMCLK
//UCSWRST (Software reset) = 1b -> normally set by a PUC
� Data rate USCI_B (master):UCB0BR0 = 0x02;
UCB0BR1 = 0x00;
// Data rate = SMCLK/2 ~= 500kHz
// UCB0BR1 = 0x00 & UCB0BR0 = 0x02
� Configure I/O ports:P3SEL |= 0x0E;
// P3.1,P3.2,P3.3 option select
UBI
>> Contents166
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (16/17)
� USI (slave) control registers:USICTL0 = 0xE3;//USICTL0 = USIPE7|USIPE6|USIPE5|USILSB|USIMST|USIGE|USIOE|USISWRST//USIPE7 (USI SDI/SDA port enable) = 1b -> USI enabled//USIPE6 (USI SDO/SCL port enable) = 1b -> USI enabled//USIPE5 (USI SCLK port enable) = 1b -> USI enabled//USILSB (LSB first) = 0b -> MSB first//USIMST (Master) = 0b -> Slave mode//USIGE (Output latch control) = 0b -> Output latch enable//USIOE (Serial data output enable) = 1b -> Output enabled//USISWRST (USI software reset) = 1b -> Software reset
MSP-EXP430F2013(slave)
SOLUTION
Using the USCI module in SPI mode included in the FG4618 (configured asmaster) of the Experimenter’s board, establish a connection to the F2013 byits USI module in SPI mode. The data exchanged is displayed by the LEDblinking.
15/01/2013
84
UBI
>> Contents167
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10b: Echo test using SPI mode (17/17)
� USI (slave) control registers:
USICTL1 = 0x10;
//USICTL1= USICKPH|USII2C|USISTTIE|USIIE|USIAL|USISTP|USISTTIFG|USIIFG
//USICKPH (Clock phase select) = 0b -> Data is changed on the first
// SCLK edge and captured on the following edge
//USII2C (I2C mode enable) = 0b -> I2C mode disabled
//USISTTIE (START condition interrupt) = 0b -> Not used
//USIIE (USI counter) = 1b -> Interrupt enabled
//USIAL (Arbitration lost) = 0b -> Not used
//USISTP (STOP condition received) = 0b -> Not used
//USISTTIFG (START condition int. flag) = 0b -> Not used
//USIIFG (USI counter int. flag) = 0b -> No int. pending
UBI
>> Contents168
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (1/21)
� Project files:
� C source files: Chapter 14 > Lab10 > Lab10c1_student.c
Chapter 14 > Lab10 > Lab10c2_student.c
� Solution files: Chapter 14 > Lab10 > Lab10c1_solution.c
Chapter 14 > Lab10 > Lab10c2_solution.c
� Overview:
� This laboratory explores the USCI and USI communication interfaces in I2C mode;
� It uses the two MSP430 devices included on the Experimenter’s board: MSP430FG4618 as the master and the MSP430F2013 as slave;
� The master receives a single byte from the slave as soon as a button connected to P1.0 is pressed.
15/01/2013
85
UBI
>> Contents169
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (2/21)
� A. Resources:
� This laboratory uses the USCI module of the MSP430FG4618 device and the USI module included in the MSP430F2013. Both units operate in I2C mode;
� The interrupts on the slave unit are generated exclusively by the USI module. They are:
• START condition on the I2C bus;
• Data reception and transmission.
� The interrupts in the master unit are provided by the USCI module. They are:
• Data reception;
• Logic level change on Port1.
UBI
>> Contents170
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (3/21)
� A. Resources:
� The resources used are:
• USCI module;
• USI module;
• Interrupts;
• I/O ports.
15/01/2013
86
UBI
>> Contents171
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (4/21)
� B. Software application organization:
� Software architecture:
UBI
>> Contents172
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (5/21)
� B. Software application organization:
� The master task is composed of two interrupt service routines:
• The S1 switch service routine is used to control the way the master receives a new data frame from the slave;
• The USCI module interrupt service routine ensures that the data sent by the slave is read by the master .
� A state machine has been implemented for the USI module of the slave unit;
� It is important to note that the states “RX Address” and “RX (N)ACK" are transient states that ensure the USI module is ready for the next activity.
15/01/2013
87
UBI
>> Contents173
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (6/21)
� B. Software application organization:
� Slave state machine:
UBI
>> Contents174
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (7/21)
� C. Configuration:
� Configure the control registers USCI_B (master):
• The connection via I2C bus is to operate as follows:
– Address slave with 7-bit address;
– Master mode;
– Single master;
– USCI clock source is SMCLK.
• Configure the following control registers based on these characteristics:
UCB0CTL0 = _______________;
UCB0CTL1 = _______________;
15/01/2013
88
UBI
>> Contents175
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (8/21)
� C. Configuration (continued):
� Data rate USCI_B (master):
• The system clock is configured to operate with a frequency of ~ 1048 kHz from the DCO;
• This frequency will be the working base for the USCI module;
• The connection operates at a clock frequency of ~ 95.3kHz. Configure the following registers:
UCB0BR0= _______________;
UCB0BR1= _______________;
UBI
>> Contents176
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (9/21)
� C. Configuration (continued):
� Ports configuration USCI_B (master):
• In order to set the external interfaces for the USCI module, it is necessary to configure the I/O ports;
• Select the USCI peripheral in I2C mode to be compatible with the connections on the Experimenter’s board:
P3SEL = __________________;
15/01/2013
89
UBI
>> Contents177
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (10/21)
� C. Configuration (continued):
� Configure the control registers USI (slave):
• The connection via I2C bus is to operate as follows:
– Slave mode;
– USI counter interrupt enable (RX and TX);
– START condition interrupt-enable;
– USIIFG is not cleared automatically.
• Configure the following control registers:
USICTL0 = _______________;
USICTL1 = _______________;
USICNT = ________________;
UBI
>> Contents178
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (11/21)
� C. Configuration (continued):
� Configure the control registers USI (slave):
• The slave unit interrupt service routine is not yet complete. The portion related to the “I2C_TX” state needs to be completed:
– Configure the USI module as an output;
– Insert the value to transmit in the transmit register;
– Configure the bit counter.
USICTL0 |=________________;
USISRL =_________________;
USICNT |=________________;
15/01/2013
90
UBI
>> Contents179
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (12/21)
� D. Analysis of operation:
� Once the USCI module is configured in accordance with the previous steps, to initiate the experiment, complete the files:
• Lab10c1_student.c (master – MSP430FG4618)
• Lab10c2_student.c (slave – MSP430F2013)
Compile them and run them on the Experimenter’s board;
� The completed solution can be found in the files Lab10c1_solution.c and Lab10c2_soluction.c.
� For this laboratory it is necessary to set up the following jumper settings:
• PWR1/2, BATT, LCL1/2, JP2;
• SPI: H1- 1&2, 3&4.
UBI
>> Contents180
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (13/21)
� D. Analysis of operation:
� Verification:• The slave data values are sent and incremented from
0x00 with each transmitted byte, and are verified by the Master;
• The LED is off for address/data Acknowledge and the LED turns on for address/data Not Acknowledge;
• The LED3 blinks at each data request:– It is turned on by a START condition;– It is turned off by the data transmit acknowledge by
the slave;(Note: the I2C bus is not released by the master
because the successive START conditions are interpreted as “repeated START”).
15/01/2013
91
UBI
>> Contents181
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (14/21)
� D. Analysis of operation:
� Verification:
• Verify the value received by setting a breakpoint in the line of code “RxBuffer = UCB0RXBUF;” of the USCI interrupt.
UBI
>> Contents182
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (15/21)
� USCI (master) control registers:UCB0CTL0 = 0x0F;//UCB0CTL0 =//UCA10|UCSLA10|UCMM|Unused|UCMST|UCMODEx|UCSYNC|//UCA10 (Own address) = 0b -> Own address (7-bit)//UCSLA10 (Slave address) = 0b -> 7-bit slave address//UCMM (Multi-master) = 0b -> Single master//Unused //UCMST (Master mode) = 1b -> Master mode//UCMODEx (USCI mode) = 11b -> I2C Mode//UCSYNC (Synchronous mode enable) = 1b -> Synchronous
MSP-EXP430FG4618 (master)
SOLUTION
Using USCI module in I2C mode included in the FG4618 (configured asmaster) of the Experimenter’s board, establish a connection to the F2013 byits USI module in I2C mode. The master receives a single byte from the slaveas soon as a button connected on P1.0 is pressed.
15/01/2013
92
UBI
>> Contents183
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (16/21)
� USCI (master) control registers:
UCB0CTL1 = 0x81;
//UCB0CTL1 =
//UCSSELx|Unused|UCTR|UCTXNACK|UCTXSTP|UCTXSTT|UCSWRST|
//UCSSELx (USCI clock source select) = 10b -> SMCLK
//Unused
//UCTR (Transmitter/Receiver) = 0b -> Receiver
//UCTXNACK (Transmit a NACK) = 0b -> Ack normally
//UCTXSTP (Transmit STOP condition) = 0b -> No STOP
//UCTXSTT (Transmit START condition) = 0b -> No START
//UCSWRST (Software reset) = 1b -> Enabled
UBI
>> Contents184
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (17/21)
� Data rate:
// DATA RATE
// data rate -> fSCL = SMCLK/11 = 95.3 kHz
UCB0BR0 = 0x0B; // fSCL = SMCLK/11 = 95.3 kHz
UCB0BR1 = 0x00;
� Configure ports:
P3SEL |=0x06; // Assign I2C pins to USCI_B0
15/01/2013
93
UBI
>> Contents185
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (18/21)
� USI (slave) control registers:USICTL0 = 0XC1;
//USICTL0 =|USIPE7|USIPE6|USIPE5|USILSB|USIMST|USIGE|USIOE|USISWRST|//USIPE7 (USI SDI/SDA port enable) = 1b -> USI function enabled//USIPE6 (USI SDO/SCL port enable) = 1b -> USI function enabled//USIPE5 (USI SCLK port enable) = 0b -> USI function disable//USILSB (LSB first) = 0b -> MSB first//USIMST (Master) = 0b -> Slave mode//USIGE (Output latch control) = 0b -> Depends on shift clock//USIOE (Serial data output enable) = 0b -> Output enabled//USISWRST (USI software reset) = 1b -> Software reset
MSP-EXP430F2013(slave)
SOLUTION
Using USCI module in I2C mode included in the FG4618 (configured asmaster) of the Experimenter’s board, establish a connection to the F2013 byits USI module in I2C mode. The master receives a single byte from the slaveas soon as a button connected on P1.0 is pressed.
UBI
>> Contents186
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (19/21)
� USI (slave) control registers:USICTL1 = 0x70;
//USICTL1 =
//|USICKPH|USII2C|USISTTIE|USIIE|USIAL|USISTP|USISTTIFG|USIIFG|
//USICKPH (Clock phase select) = 0b -> Data is changed
// on the first SCLK edge and captured on the following edge.
//USII2C (I2C mode enable) = 1b -> I2C mode enabled
//USISTTIE = 1b -> Interrupt on START condition enabled
//USIIE = 1b -> USI counter interrupt enable
//USIAL (Arbitration lost) = 0b -> Not used
//USISTP (STOP condition received) = 0b -> Not used
//USISTTIFG (START condition int. flag) = 0b -> Not used
//USIIFG (USI counter int. flag) = 0b -> No int. pending
15/01/2013
94
UBI
>> Contents187
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (20/21)
� USI Bit Counter Register:
USICNT |= 0x20;
//USICNT =
//USISCLREL| USI16B |USIIFGCC |USICNTx|
//USISCLREL (SCL release) = 0b -> SCL line is held low
// if USIIFG is set
//USI16B (16-bit shift register enable) = 0b -> 8-bit
// shift register mode
//USIIFGCC (USI int. flag clear control) = 1b -> USIIFG
// is not cleared automatically
//USICNTx (USI bit count) = 00000b (not relevant)
UBI
>> Contents188
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Lab10c: Echo test using I2C mode (21/21)
� I2C state machine:
USICTL0 |= USIOE; // SDA = output
USISRL = SlaveData; // Send data byte
USICNT |= 0x08; // Bit counter = 8, TX data
15/01/2013
95
UBI
>> Contents189
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (1/4)
� 1. The USI module has:
(a) A SPI interface;
(b) An I2C interface;
(c) All of above;
(d) None of above.
� 2. The internal USI clock generation can use:
(a) ACLK and SMCLK;
(b) ACLK and MCLK;
(c) SMCLK and MCLK;
(d) None of above.
UBI
>> Contents190
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (2/4)
� 3. The USISR shift register supports:
(a) 8 bits;
(b) 16 bits;
(c) All of above;
(d) None of above.
� 4. The USIIFG is set when:
(a) Bit counter counts to 0xFF;
(b) Bit counter counts to 0x00;
(c) Bit counter counts to 0x80;
(d) Bit counter counts to 0x08.
15/01/2013
96
UBI
>> Contents191
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (3/4)
� 5. After address/data reception, the receiver ACK/NACK is:
(a) SDA = input: 0 = ACK, 1 = NACK;
(b) SDA = output: 0 = ACK, 1 = NACK;
(c) SDA = input: 1 = ACK, 0 = NACK;
(d) SDA = output: 1 = ACK, 0 = NACK.
� 6. After address/data transmission the transmitter ACK/NACK is:
(a) SDA = input: 0 = ACK, 1 = NACK;
(b) SDA = output: 0 = ACK, 1 = NACK;
(c) SDA = input: 1 = ACK, 0 = NACK;
(d) SDA = output: 1 = ACK, 0 = NACK.
UBI
>> Contents192
Copyright 2009 Texas Instruments All Rights Reserved
www.msp430.ubi.pt
Quiz (4/4)
� Answers:
1. (c) All of above.
2. (a) ACLK and SMCLK.
3. (c) All of above.
4. (b) Bit counter counts to 0x00.
5. (b) SDA = output: 0 = ACK, 1 = NACK.
6. (a) SDA = input: 0 = ACK, 1 = NACK.
top related