LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI

Size: px
Start display at page:

Download "LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI"

Transcription

1 LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI Laboratory Lesson 7: Universal Serial Asynchronous Receiver Transmitter (USART) Prof. Luca Benini <luca.benini@unibo.it> Prof Davide Rossi <davide.rossi@unibo.it> Simone Benatti <simone.benatti@unibo.it> Victor Kartsch<victorjavier.kartsch@unibo.it>

2 Info & Communications

3 Recap LAB1: IDE & Debug LAB2: GPIO & Systick LAB3: Advanced Debug LAB4: EXTI LAB5:TIMERS LAB6:DMA and FLASH LAB7: USART Universal Serial (Asyncronous) Receiver Transmitter

4 Universal Serial Asynchronous Receiver Transmitter (USART)

5 Serial communications Parallel world Serial world Vs Without using a lot of I/O lines I/O lines require I/O pads which cost $$$ and size I/O lines require PCB area which costs $$$ and size connect different systems together Two embedded systems A desktop and an embedded system connect different chips together in the same embedded system MCU to peripheral MCU to MCU

6 USART intuition Easily connect your embedded system with the external world Safe world Non protected world MCU Transceiver 232 Logic levels 0 -> 3.3V

7 USART protocol Send the ASCII letter W ( )

8 USART

9 USART Characteristics The USART is the most used serial communication interface (eg. PC RS232 interface, IC communication interface, BT and WiFi module interface) FEATURES: Full duplex, asynchronous communications Fractional baud rate generator systems A common programmable transmit and receive baud rates up to 4.5 MBits/s Programmable data word length (8 or 9 bits) Configurable stop bits - support for 1 or 2 stop bits Transmitter clock output for synchronous transmission Single wire half duplex communication Configurable multibuffer communication using DMA Buffering of received/transmitted bytes in reserved SRAM using centralized DMA Separate enable bits for Transmitter and Receiver

10 USART Configuration Each character is sent using: a logic low start bit one or more logic high stop bits one optional parity bit number of data bits (usually 8 or 9) bit timing ( baud rate ) N-1

11 USART Characteristics FLAGS: Receive buffer full Transmit buffer empty End of Transmission Parity control: Transmits parity bit Checks parity of received data byte Four error detection: Overrun error Noise error Frame error Parity error Ten interrupt sources with flags: CTS changes Transmit data register empty Transmission complete Receive data register full Idle line received Overrun error Framing error Noise error Parity error Multiprocessor communication - enter into mute mode if address match does not occur

12 USART Block diagram Data registers Interface pins Control registers Baud Rate Generator

13 USART Functional description Any USART bidirectional communication requires a minimum of two pins: Receive Data In (RX): Receive Data Input is the serial data input. Oversampling techniques are used for data recovery by discriminating between valid incoming data and noise. Transmit Data Out (TX): When the transmitter is disabled, the output pin returns to its I/O port configuration. When it is enabled and nothing is to be transmitted, the TX pin is at high level. In single-wire and smartcard modes, this I/O is used to transmit and receive the data. Through these pins, serial data is transmitted and received in normal USART mode as frames comprising: An Idle Line prior to transmission or reception, a start bit, the data word (8 or 9 bits) least significant bit first and stop bits (0.5,1, 1.5 or 2 stop bits) indicating that the frame is complete. The following pin is required to interface in synchronous mode: SCLK: Transmitter clock output. This pin outputs the transmitter data clock for synchronous transmission corresponding to SPI master mode. The following pins are required in Hardware flow control mode: ncts: Clear To Send blocks the data transmission at the end of the current transfer when high nrts: Request to send indicates that the USART is ready to receive a data (when low).

14 USART Tx/Rx Char transmission When the transmit enable bit (TE) is set, the data in the transmit shift register is output on the TX pin and the corresponding clock pulses are output on the CK pin. During a USART transmission, data shifts out least significant bit first on the TX pin. In this mode, the USART_DR register consists of a buffer (TDR) between the internal bus and the transmit shift register. Every character is preceded by a start bit which is a logic level low for one bit period. Every character is terminated by a configurable number of stop bits: 0.5, 1, 1.5 and 2 stop bits. The TE bit should not be reset during transmission of data. Resetting the TE bit during the transmission will corrupt the data on the TX pin as the baud rate counters will get frozen. The current data being transmitted will be lost. An idle frame will be sent after the TE bit is enabled. Char reception The USART can receive data words of either 8 or 9 bits depending on the M bit in the USART_CR1 register. During a USART reception, data shifts in least significant bit first through the RX pin. In this mode, the USART_DR register consists of a buffer (RDR) between the internal bus and the received shift register.

15 USART Registers Status register Data register Baud Rate register Control register 1 Control register 2 Control register 3 Prescaler register

16 USART Interrupts The USART interrupt events are connected to the same interrupt routine During transmission: Transmission Complete, Clear to Send or Transmit Data Register empty interrupt. While receiving: Idle Line detection, Overrun error, Receive Data register not empty, Parity error, LIN break detection, Noise Flag (only in multi buffer communication) and Framing Error (only in multi buffer communication). These events generate an interrupt if the corresponding Enable Control Bit is set.

17 USART Low level procedure TX 1. Enable the USART by writing the UE bit in USART_CR1 register to Program the M bit in USART_CR1 to define the word length. 3. Program the number of stop bits in USART_CR2. 4. Select the desired baud rate using the USART_BRR register. 5. Set the TE bit in USART_CR1 to send an idle frame as first transmission. 6. Write the data to send in the USART_DR register (this clears the TXE bit). Repeat this for each data to be transmitted in case of single buffer. 7. After writing the last data into the USART_DR register, wait until TC=1. This indicates that the transmission of the last frame is complete. This is required for instance when the USART is disabled or enters the Halt mode to avoid corrupting the last transmission. Single byte communication The TXE bit is always cleared by a write to the data register. The TXE bit is set by hardware and it indicates: The data has been moved from TDR to the shift register and the data transmission has started. The TDR register is empty. The next data can be written in the USART_DR register without overwriting the previous data. This flag generates an interrupt if the TXEIE bit is set.

18 USART Low level procedure RX 1. Enable the USART by writing the UE bit in USART_CR1 register to Program the M bit in USART_CR1 to define the word length. 3. Program the number of stop bits in USART_CR2. 4. Select the desired baud rate using the baud rate register USART_BRR 5. Set the RE bit USART_CR1. This enables the receiver which begins searching for a start bit Single byte communication The RXNE bit is set. It indicates that the content of the shift register is transferred to the RDR. In other words, data has been received and can be read (as well as its associated error flags). An interrupt is generated if the RXNEIE bit is set. The error flags can be set if a frame error, noise or an overrun error has been detected during reception. In single buffer mode, clearing the RXNE bit is performed by a software read to the USART_DR register. The RXNE flag can also be cleared by writing a zero to it. In multi-buffer, RXNE is set after every byte received and is cleared by the DMA read to the Data Register.

19 USART (what) I want to use an USART. What do I need to know? Which bus USARTx are connected to? Look at the architecture diagram Which Pin and Port are we going to use? Look at the development board documentation What do I need to do with this USART? (input, output,...) Configure as: Baud Rate 9600, 8 bit data, No Parity, 1 stop bit

20 USART Examples The operation that are needed to use the USART are: Initialization of the USART PINs as Alternate Function (NOT standard GPIO) Initialization of USART Write data in the Data Register / read data from Data Register Example 1: polling Send a character and receive it back (loopback) and check if it is correct Example 2: interrupt Same as Example 1 with RX/TX interrupts

21 Example 1: polling

22 USART GPIO config GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* Connect PA2 to USART2_Tx*/ GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); /* Connect PA3 to USART2_Rx*/ GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; Pins are used in Alternate Function: not used as GPIO, but as USART pin GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_Init(GPIOA, &GPIO_InitStructure);

23 USART - Initialization USART_InitTypeDef USART_InitStructure; /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); Structure definition /* USARTx configured as follows: - BaudRate = baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = ; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx USART_Mode_Tx; /* USART initialization */ USART_Init(USART2, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART2, ENABLE);

24 USART - Initialization USART_InitTypeDef USART_InitStructure; /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* USARTx configured as follows: - BaudRate = baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = ; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx USART_Mode_Tx; /* USART initialization */ USART_Init(USART2, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART2, ENABLE); Clock Enable

25 USART - Initialization USART_InitTypeDef USART_InitStructure; /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* USARTx configured as follows: - BaudRate = baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = ; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx USART_Mode_Tx; /* USART initialization */ USART_Init(USART2, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART2, ENABLE); Set the baudrate To communicate, two USART devices connected must have the same baud rate

26 USART - Initialization USART_InitTypeDef USART_InitStructure; /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* USARTx configured as follows: - BaudRate = baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = ; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx USART_Mode_Tx; /* USART initialization */ USART_Init(USART2, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART2, ENABLE); Configure USART for: no parity bit, 1 stop bit and 8 bit word length

27 USART - Initialization USART_InitTypeDef USART_InitStructure; /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* USARTx configured as follows: - BaudRate = baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = ; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx USART_Mode_Tx; /* USART initialization */ USART_Init(USART2, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART2, ENABLE); Do not use hardware flow control (requires two additional lines for handshaking)

28 USART - Initialization USART_InitTypeDef USART_InitStructure; /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* USARTx configured as follows: - BaudRate = baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = ; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx USART_Mode_Tx; /* USART initialization */ USART_Init(USART2, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART2, ENABLE); Enable TX and RX

29 USART - Initialization USART_InitTypeDef USART_InitStructure; /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* USARTx configured as follows: - BaudRate = baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = ; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx USART_Mode_Tx; /* USART initialization */ USART_Init(USART2, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART2, ENABLE); Initialize and enable USART2

30 USART main while(1) if (readytosend == 1) /* Send one byte */ USART_SendData(USART2, chartosend); In this example we enable the data transmission every 1s (look in the systick) /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) /* Loop until a character is received */ while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) /* Read one byte */ chartoread = USART_ReceiveData(USART2); if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); else STM_EVAL_LEDOn(LED5); chartosend++; readytosend = 0;

31 USART main while(1) if (readytosend == 1) /* Send one byte */ USART_SendData(USART2, chartosend); Send one Byte /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) /* Loop until a character is received */ while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) /* Read one byte */ chartoread = USART_ReceiveData(USART2); if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); else STM_EVAL_LEDOn(LED5); chartosend++; readytosend = 0;

32 USART main while(1) if (readytosend == 1) /* Send one byte */ USART_SendData(USART2, chartosend); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) /* Loop until a character is received */ while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) /* Read one byte */ chartoread = USART_ReceiveData(USART2); if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); else STM_EVAL_LEDOn(LED5); Wait until the end of transmission Polling = active wait chartosend++; readytosend = 0;

33 USART main while(1) if (readytosend == 1) /* Send one byte */ USART_SendData(USART2, chartosend); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) /* Loop until a character is received */ while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) /* Read one byte */ chartoread = USART_ReceiveData(USART2); if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); else STM_EVAL_LEDOn(LED5); Wait until something is received Polling = active wait chartosend++; readytosend = 0;

34 USART main while(1) if (readytosend == 1) /* Send one byte */ USART_SendData(USART2, chartosend); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) /* Loop until a character is received */ while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) /* Read one byte */ chartoread = USART_ReceiveData(USART2); if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); else STM_EVAL_LEDOn(LED5); Read one Byte chartosend++; readytosend = 0;

35 USART main while(1) if (readytosend == 1) /* Send one byte */ USART_SendData(USART2, chartosend); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) /* Loop until a character is received */ while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) /* Read one byte */ chartoread = USART_ReceiveData(USART2); if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); else STM_EVAL_LEDOn(LED5); Check if received is equal to sent and turn on led chartosend++; readytosend = 0;

36 Example 2: interrupt

37 USART Interrupts In Example 1 we have active waiting for data reception and transmission -> NOT efficient Interrupt can signal when new data is available (RX) or when to write new data to send (TX). One shared handler: check which flag is active Flags to be enabled: RXNE: Received Data Ready to Read TXE: Transmit Data Register Empty

38 Code - NVIC NVIC_InitTypeDef NVIC_InitStructure; /* Enable the USART2 RX Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the RX Interrupt */ USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); Configure Interrupt for USART2

39 Code - NVIC NVIC_InitTypeDef NVIC_InitStructure; /* Enable the USART2 RX Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the RX Interrupt */ USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); Enable RX Interrupt for USART2

40 Code USART ISR void USART2_IRQHandler(void) /* RX interrupt */ if (USART_GetITStatus(USART2, USART_IT_RXNE)!= RESET) /* Read data and store in RX buffer */ bufferrx[idxrx++] = USART_ReceiveData(USART2); datareceived = 1; Check if RXNE flag caused interrupt /* check index and buffer size */ if (idxrx >= RX_BUFFER_SIZE) idxrx = 0; /* TX Data Register Empty interrupt */ if (USART_GetITStatus(USART2, USART_IT_TXE)!= RESET) if (idxtx < nbytestx) /* there are still bytes to send */ USART_SendData(USART2, (u8)buffertx[idxtx++]); else /* All bytes sent, disable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, DISABLE);

41 Code USART ISR void USART2_IRQHandler(void) /* RX interrupt */ if (USART_GetITStatus(USART2, USART_IT_RXNE)!= RESET) /* Read data and store in RX buffer */ bufferrx[idxrx++] = USART_ReceiveData(USART2); datareceived = 1; /* check index and buffer size */ if (idxrx >= RX_BUFFER_SIZE) idxrx = 0; Every time a new character is received, it is copied into a buffer /* TX Data Register Empty interrupt */ if (USART_GetITStatus(USART2, USART_IT_TXE)!= RESET) if (idxtx < nbytestx) /* there are still bytes to send */ USART_SendData(USART2, (u8)buffertx[idxtx++]); else /* All bytes sent, disable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, DISABLE);

42 Code USART ISR void USART2_IRQHandler(void) /* RX interrupt */ if (USART_GetITStatus(USART2, USART_IT_RXNE)!= RESET) /* Read data and store in RX buffer */ bufferrx[idxrx++] = USART_ReceiveData(USART2); datareceived = 1; /* check index and buffer size */ if (idxrx >= RX_BUFFER_SIZE) idxrx = 0; We set a flag to signal the data has been received /* TX Data Register Empty interrupt */ if (USART_GetITStatus(USART2, USART_IT_TXE)!= RESET) if (idxtx < nbytestx) /* there are still bytes to send */ USART_SendData(USART2, (u8)buffertx[idxtx++]); else /* All bytes sent, disable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, DISABLE);

43 Code USART ISR void USART2_IRQHandler(void) /* RX interrupt */ if (USART_GetITStatus(USART2, USART_IT_RXNE)!= RESET) /* Read data and store in RX buffer */ bufferrx[idxrx++] = USART_ReceiveData(USART2); datareceived = 1; /* check index and buffer size */ if (idxrx >= RX_BUFFER_SIZE) idxrx = 0; Check index to not exceed buffer size /* TX Data Register Empty interrupt */ if (USART_GetITStatus(USART2, USART_IT_TXE)!= RESET) if (idxtx < nbytestx) /* there are still bytes to send */ USART_SendData(USART2, (u8)buffertx[idxtx++]); else /* All bytes sent, disable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, DISABLE);

44 Code USART ISR void USART2_IRQHandler(void) /* RX interrupt */ if (USART_GetITStatus(USART2, USART_IT_RXNE)!= RESET) /* Read data and store in RX buffer */ bufferrx[idxrx++] = USART_ReceiveData(USART2); datareceived = 1; /* check index and buffer size */ if (idxrx >= RX_BUFFER_SIZE) idxrx = 0; /* TX Data Register Empty interrupt */ if (USART_GetITStatus(USART2, USART_IT_TXE)!= RESET) if (idxtx < nbytestx) /* there are still bytes to send */ USART_SendData(USART2, (u8)buffertx[idxtx++]); else /* All bytes sent, disable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, DISABLE); Check if TXE flag caused interrupt

45 Code USART ISR void USART2_IRQHandler(void) /* RX interrupt */ if (USART_GetITStatus(USART2, USART_IT_RXNE)!= RESET) /* Read data and store in RX buffer */ bufferrx[idxrx++] = USART_ReceiveData(USART2); datareceived = 1; /* check index and buffer size */ if (idxrx >= RX_BUFFER_SIZE) idxrx = 0; /* TX Data Register Empty interrupt */ if (USART_GetITStatus(USART2, USART_IT_TXE)!= RESET) if (idxtx < nbytestx) /* there are still bytes to send */ USART_SendData(USART2, (u8)buffertx[idxtx++]); else /* All bytes sent, disable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, DISABLE); If index has not reached number of bytes to send: send one byte from TX buffer and increase index

46 Code USART ISR void USART2_IRQHandler(void) /* RX interrupt */ if (USART_GetITStatus(USART2, USART_IT_RXNE)!= RESET) /* Read data and store in RX buffer */ bufferrx[idxrx++] = USART_ReceiveData(USART2); datareceived = 1; /* check index and buffer size */ if (idxrx >= RX_BUFFER_SIZE) idxrx = 0; /* TX Data Register Empty interrupt */ if (USART_GetITStatus(USART2, USART_IT_TXE)!= RESET) if (idxtx < nbytestx) /* there are still bytes to send */ USART_SendData(USART2, (u8)buffertx[idxtx++]); else /* All bytes sent, disable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, DISABLE); When finished disable TX interrupt

47 Code - globals #define RX_BUFFER_SIZE 64 #define TX_BUFFER_SIZE 64 void USART_Config(void); Function declarations u8 bufferrx[rx_buffer_size]; u8 buffertx[tx_buffer_size]; u8 idxrx = 0; u8 idxtx = 0; u8 nbytestx = 0; u8 readytosend = 0; u8 datareceived = 0; Buffer and index for TX and RX. Exchange data between main and ISR State variables

48 Code - main while (1) if (readytosend == 1) buffertx[0] = chartosend; nbytestx = 1; idxtx = 0; As in Example 1, we send a Byte every 1s NO active wait, just check flag /* Enable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, ENABLE); readytosend = 0;...

49 Code - main while (1) if (readytosend == 1) buffertx[0] = chartosend; nbytestx = 1; idxtx = 0; Copy data to send in TX buffer Set #Bytes to send and init index = 0 /* Enable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, ENABLE); readytosend = 0;...

50 Code - main while (1) if (readytosend == 1) buffertx[0] = chartosend; nbytestx = 1; idxtx = 0; /* Enable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, ENABLE);... readytosend = 0; Enable TX interrupt. NOTE: TX interrupt is usually disabled, only when the buffer to send is ready we enable it

51 Code - main while (1) if (readytosend == 1) buffertx[0] = chartosend; nbytestx = 1; idxtx = 0; /* Enable TX interrupt */ USART_ITConfig(USART2, USART_IT_TXE, ENABLE);... readytosend = 0; We clear our Flag

52 Code - main while (1)... if (datareceived == 1) chartoread = bufferrx[idxrx-1]; if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); STM_EVAL_LEDOff(LED5); else STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOn(LED5); Check the flag for data received. NO active wait, just check flag chartosend++; idxrx = 0; datareceived = 0;

53 Code - main while (1)... if (datareceived == 1) chartoread = bufferrx[idxrx-1]; if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); STM_EVAL_LEDOff(LED5); else STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOn(LED5); Get data from RX buffer. chartosend++; idxrx = 0; datareceived = 0;

54 Code - main while (1)... if (datareceived == 1) chartoread = bufferrx[idxrx-1]; if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); STM_EVAL_LEDOff(LED5); else STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOn(LED5); Check if received is equal to sent and turn on led. chartosend++; idxrx = 0; datareceived = 0;

55 Code - main while (1)... if (datareceived == 1) chartoread = bufferrx[idxrx-1]; if (chartoread == chartosend) STM_EVAL_LEDOn(LED4); STM_EVAL_LEDOff(LED5); else STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOn(LED5); chartosend++; idxrx = 0; datareceived = 0; Change Byte to send; reset index and flag.

56 Weekly Assignments

57 USART Exercises 1. Starting from example 1 send an array of characters periodically each 50ms using polling The array should end with character \r and you should use this to know when to stop sending. Example: char chartosend[] = 'c', 'i', 'a', 'o', '\r'; hint: use systick to periodically enable the data transmission hint: you send and receive one character at a time untill you reach the end character 2. Starting from example 2 send and receive an array of character periodically each 50ms using the interrupts. Same as es. 1 but with interrupts 3. (Optional and Extra fun!) Starting from example 2 send and receive an array of 4 to 10 characters periodically each 50ms using the interrupts. Once you receive the n-char packet you add +1 to the last element and you duplicate it in the n+1 position, and then you resend it (see next page) hint: try a FSM 4 char 5 char 6 char 7 char 4 char 5 char 6 char 7 char

58 USART Exercises

59 USART Questions 1. Which flags must be checked and which registers must be written to send something via USART? 2. Describe the following flags: TXE, TC e RXNE (look at the reference manual)

USART. USART stands for Universal Synchronous Asynchronous Receiver Transmitter. Full-duplex NRZ asynchronous serial data transmission

USART. USART stands for Universal Synchronous Asynchronous Receiver Transmitter. Full-duplex NRZ asynchronous serial data transmission USART 1 USART USART stands for Universal Synchronous Asynchronous Receiver Transmitter Full-duplex NRZ asynchronous serial data transmission Offer wide ranges of baud rate 2 Serial communication Can support

More information

Learn how to communicate

Learn how to communicate USART 1 Learn how to communicate Programmed I/O (Software Polling) Interrupt Driven I/O Direct Memory Access (DMA) 2 Programmed I/O (Polling) Processor must read and check I/O ready bits for proper value

More information

void GPIO_setup(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA RCC_APB2Periph_GPIOC RCC_APB2Periph_AFIO,ENABLE);

void GPIO_setup(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA RCC_APB2Periph_GPIOC RCC_APB2Periph_AFIO,ENABLE); UART Interrupt 1 Example of program u8 TxBuffer[100] = \rusart1 Transmission using interrupt \r\n ; u8 RxMessage[2] = [0]; u8 RxUpdate=0; u8 TxReady = 1; int main(){ RCC_setup(); GPIO_setup(); NVIC_setup();

More information

MeD SeS Worksheet 4 11/01/18

MeD SeS Worksheet 4 11/01/18 Title: Serial data communication Author: Craig Duffy 9/9/14, 11/01/18 Module: Mobile and Embedded Devices, Secure Embedded Systems Awards: BSc CSI, BSc Forensic Computing, Computer Security. Prerequisites:

More information

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI. Laboratory Lesson 9: Serial Peripheral Interface (SPI)

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI. Laboratory Lesson 9: Serial Peripheral Interface (SPI) LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI Laboratory Lesson 9: Serial Peripheral Interface (SPI) Prof. Luca Benini Prof Davide Rossi

More information

W7200 User s Guide. for STM32F10x Standard Library. - USART - GPIO - Timer. Version 1.0.0e

W7200 User s Guide. for STM32F10x Standard Library. - USART - GPIO - Timer. Version 1.0.0e W7200 User s Guide for STM32F10x Standard Library - USART - GPIO - Timer Version 1.0.0e 2013 WIZnet Co., Inc. All Rights Reserved. For more information, visit our website at http://www.wiznet.co.kr Table

More information

STM32F4 Standard Peripheral Library. EE599: Real-Time Operating Systems University of Kentucky. Dr. Samir Rawashdeh

STM32F4 Standard Peripheral Library. EE599: Real-Time Operating Systems University of Kentucky. Dr. Samir Rawashdeh STM32F4 Standard Peripheral Library EE599: Real-Time Operating Systems University of Kentucky Dr. Samir Rawashdeh Includes material by: - ST Reference Material 1 Include files STM32F10x_StdPeriph_Driver

More information

Hello, and welcome to this presentation of the STM32 Low Power Universal Asynchronous Receiver/Transmitter interface. It covers the main features of

Hello, and welcome to this presentation of the STM32 Low Power Universal Asynchronous Receiver/Transmitter interface. It covers the main features of Hello, and welcome to this presentation of the STM32 Low Power Universal Asynchronous Receiver/Transmitter interface. It covers the main features of this interface, which is widely used for serial communications.

More information

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI. Laboratory Lesson 2: - General Purpose I/O - SysTick

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI. Laboratory Lesson 2: - General Purpose I/O - SysTick LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI Laboratory Lesson 2: - General Purpose I/O - SysTick Prof. Luca Benini Prof Davide Rossi

More information

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features of this USART interface, which is widely used for serial

More information

EE 354 November 13, 2017 ARM UART Notes

EE 354 November 13, 2017 ARM UART Notes EE 354 November 13, 2017 ARM UART Notes For serial communications you should be familiar with the following terms: UART/USART Baud rate Synchronous/Asynchronous communication Half-Duplex/Full-Duplex The

More information

Curtain Control Systems Development on Mesh Wireless Network of the Smart Home

Curtain Control Systems Development on Mesh Wireless Network of the Smart Home Bulletin of Electrical Engineering and Informatics Vol. 7, No. 4, December 2018, pp. 615~625 ISSN: 2302-9285, DOI: 10.11591/eei.v7i4.1199 615 Curtain Control Systems Development on Mesh Wireless Network

More information

C:\Users\Bryan\Documents\RIT\Senior Design\P14345\web\public\FinalDocuments\main.c

C:\Users\Bryan\Documents\RIT\Senior Design\P14345\web\public\FinalDocuments\main.c ****************************************************************************** * @file System / main.c * @author P14345 * @version V1.1.0 * @date 11/6/14 * @brief Program body ******************************************************************************

More information

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI Laboratory Lesson 5: -Timers Prof. Luca Benini Simone Benatti Bojan Milosevic

More information

Informatics for industrial applications

Informatics for industrial applications Informatics for industrial applications Lecture 5 - Peripherals: USART and DMA Martino Migliavacca martino.migliavacca@gmail.com October 20, 2011 Outline 1 Introduction to USART Introduction Synchronous

More information

Concepts of Serial Communication

Concepts of Serial Communication Section 6. Serial Communication Communication Using Serial Interfaces: UART and SPI Concepts of Serial Communication Limitations of Parallel Bus Clock skew becomes a serious issue for high speed and long

More information

Embedded Systems and Software. Serial Communication

Embedded Systems and Software. Serial Communication Embedded Systems and Software Serial Communication Slide 1 Using RESET Pin on AVRs Normally RESET, but can be configured via fuse setting to be general-purpose I/O Slide 2 Disabling RESET Pin on AVRs Normally

More information

Embedded Systems and Software

Embedded Systems and Software Embedded Systems and Software Serial Communication Serial Communication, Slide 1 Lab 5 Administrative Students should start working on this LCD issues Caution on using Reset Line on AVR Project Posted

More information

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI Laboratory Lesson 10: CMSIS DSP Library and Functions Final Assignment Prof. Luca Benini Prof Davide

More information

MCS-51 Serial Port A T 8 9 C 5 2 1

MCS-51 Serial Port A T 8 9 C 5 2 1 MCS-51 Serial Port AT89C52 1 Introduction to Serial Communications Serial vs. Parallel transfer of data Simplex, Duplex and half-duplex modes Synchronous, Asynchronous UART Universal Asynchronous Receiver/Transmitter.

More information

OUTLINE. SPI Theory SPI Implementation STM32F0 SPI Resources System Overview Registers SPI Application Initialization Interface Examples

OUTLINE. SPI Theory SPI Implementation STM32F0 SPI Resources System Overview Registers SPI Application Initialization Interface Examples SERIAL PERIPHERAL INTERFACE (SPI) George E Hadley, Timothy Rogers, and David G Meyer 2018, Images Property of their Respective Owners OUTLINE SPI Theory SPI Implementation STM32F0 SPI Resources System

More information

Serial Communications

Serial Communications 1 Serial Interfaces 2 Embedded systems often use a serial interface to communicate with other devices. Serial Communications Serial implies that it sends or receives one bit at a time. Serial Interfaces

More information

INTRODUCTION TO FLEXIO

INTRODUCTION TO FLEXIO INTRODUCTION TO FLEXIO Osvaldo Romero Applications Engineer EXTERNAL USE Agenda Introduction to FlexIO FlexIO Main Features FlexIO Applications Freescale Products with FlexIO Collaterals\Tools for FlexIO

More information

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Microcontroller It is essentially a small computer on a chip Like any computer, it has memory,

More information

Universität Dortmund. IO and Peripheral Interfaces

Universität Dortmund. IO and Peripheral Interfaces IO and Peripheral Interfaces Microcontroller System Architecture Each MCU (micro-controller unit) is characterized by: Microprocessor 8,16,32 bit architecture Usually simple in-order microarchitecture,

More information

Device: MOD This document Version: 1.0. Matches module version: v3 [29 June 2016] Date: 23 October 2017

Device: MOD This document Version: 1.0. Matches module version: v3 [29 June 2016] Date: 23 October 2017 Device: MOD-1025 This document Version: 1.0 Matches module version: v3 [29 June 2016] Date: 23 October 2017 Description: UART (async serial) to I2C adapter module MOD-1025 v3 datasheet Page 2 Contents

More information

Rochester Institute of Technology CMPE 663/EEEE 663 Graduate Student Project

Rochester Institute of Technology CMPE 663/EEEE 663 Graduate Student Project Rochester Institute of Technology CMPE 663/EEEE 663 Graduate Student Project Graduate Student Project: Extend the USART Demo project to include blocking and non-blocking (interrupt driven) versions of

More information

For reference only Refer to the latest documents for details

For reference only Refer to the latest documents for details STM32F3 Technical Training For reference only Refer to the latest documents for details Serial peripheral interface SPI 3 SPI Features (1/2) 3 Full duplex synchronous transfers (3 lines) Half duplex/simplex

More information

Serial Communication. Simplex Half-Duplex Duplex

Serial Communication. Simplex Half-Duplex Duplex 1.5. I/O 135 Serial Communication Simplex Half-Duplex Duplex 136 Serial Communication Master-Slave Master Master-Multi-Slave Master Slave Slave Slave (Multi-)Master Multi-Slave Master Slave Slave Slave

More information

Serial Peripheral Interface (SPI)

Serial Peripheral Interface (SPI) SPI and I 2 C 1 Serial Peripheral Interface (SPI) SPI allow half/full duplex, synchronous, serial communication with external devices The interface can be configured as master for MCU board Communication

More information

AN Multifunction Serial Interface of FM MCU. Contents. 1 Introduction

AN Multifunction Serial Interface of FM MCU. Contents. 1 Introduction AN99218 Author: Edison Zhang Associated Part Family: FM0+, FM3, FM4 Associated Code Examples: None Related Application Notes: None AN99218 explains the various modes of the multifunction serial (MFS) interface.

More information

SCI Serial Communication Interface

SCI Serial Communication Interface SCI Serial Communication Interface Gerrit Becker James McClearen Charlie Hagadorn October 21, 2004 1 Learning Objectives of the Overview Knowledge of the general differences between serial and parallel

More information

STM32F4 Labs. T.O.M.A.S Technically Oriented Microcontroller Application Services V1.07

STM32F4 Labs. T.O.M.A.S Technically Oriented Microcontroller Application Services V1.07 STM32F4 Labs T.O.M.A.S Technically Oriented Microcontroller Application Services V1.07 CONTENT 1/3 2 1. GPIO lab 2. EXTI lab 3. SLEEP lab 4. STOP lab 5. STANDBY lab 6. DMA Poll lab 7. DMA Interrupt lab

More information

ECE/CS 5780/6780: Embedded System Design

ECE/CS 5780/6780: Embedded System Design ECE/CS 5780/6780: Embedded System Design Scott R. Little Lecture 16: SCI Register Configuration and Ritual Scott R. Little (Lecture 16: SCI Config) ECE/CS 5780/6780 1 / 19 Administrivia Schedule This is

More information

AN-1435 APPLICATION NOTE

AN-1435 APPLICATION NOTE APPLICATION NOTE One Technology Way P.O. Box 9106 Norwood, MA 02062-9106, U.S.A. Tel: 781.329.4700 Fax: 781.461.3113 www.analog.com Implementing UART Using the ADuCM3027/ADuCM3029 Serial Ports INTRODUCTION

More information

COMP2121: Microprocessors and Interfacing

COMP2121: Microprocessors and Interfacing COMP2121: Microprocessors and Interfacing Lecture 25: Serial Input/Output (II) Overview USART (Universal Synchronous and Asynchronous serial Receiver and Transmitter) in AVR http://www.cse.unsw.edu.au/~cs2121

More information

ECE251: Thursday November 8

ECE251: Thursday November 8 ECE251: Thursday November 8 Universal Asynchronous Receiver & Transmitter Text Chapter 22, Sections 22.1.1-22.1.4-read carefully TM4C Data Sheet Section 14-no need to read this A key topic but not a lab

More information

CS/ECE 5780/6780: Embedded System Design

CS/ECE 5780/6780: Embedded System Design CS/ECE 5780/6780: Embedded System Design John Regehr Lecture 16: SCI Register Configuration and Ritual SCI Register Information & Terminology The information in this lecture is found: Textbook pages 346-9.

More information

Addressing scheme to address a specific devices on a multi device bus Enable unaddressed devices to automatically ignore all frames

Addressing scheme to address a specific devices on a multi device bus Enable unaddressed devices to automatically ignore all frames 23. USART 23.1 Features Full-duplex operation Asynchronous or synchronous operation Synchronous clock rates up to 1/2 of the device clock frequency Asynchronous clock rates up to 1/8 of the device clock

More information

RL78 Serial interfaces

RL78 Serial interfaces RL78 Serial interfaces Renesas Electronics 00000-A Introduction Purpose This course provides an introduction to the RL78 serial interface architecture. In detail the different serial interfaces and their

More information

Universal Asynchronous Receiver / Transmitter (UART)

Universal Asynchronous Receiver / Transmitter (UART) Universal Asynchronous Receiver / Transmitter (UART) MSP432 UART 2 tj MSP432 UART ARM (AMBA Compliant) Asynchronous operation 7/8 bit transmission Master/Slave LSB/MSB first Separate RX/TX registers 4

More information

Introduction USART & AVR EVK1100

Introduction USART & AVR EVK1100 Introduction USART & AVR EVK1100 Time scope: 2-4h USART (Theory) Flash Development board EVK 1100 Basics for programming USART (Driver, Code) Exercises Emqopter GmbH 2 Terminology: UART, Universal Asynchronous

More information

Interfacing a Hyper Terminal to the Flight 86 Kit

Interfacing a Hyper Terminal to the Flight 86 Kit Experiment 6 Interfacing a Hyper Terminal to the Flight 86 Kit Objective The aim of this lab experiment is to interface a Hyper Terminal to 8086 processor by programming the 8251 USART. Equipment Flight

More information

8051 Serial Communication

8051 Serial Communication 8051 Serial Communication Basics of serial communication Parallel: transfers eight bits of data simultaneously over eight data lines expensive - short distance fast Serial : one bit at a time is transferred

More information

Engineer-to-Engineer Note

Engineer-to-Engineer Note Engineer-to-Engineer Note EE-391 Technical notes on using Analog Devices products and development tools Visit our Web resources http://www.analog.com/ee-notes and http://www.analog.com/processors or e-mail

More information

Innovati s Bluetooth 100M Universal Wireless Bluetooth Module

Innovati s Bluetooth 100M Universal Wireless Bluetooth Module Innovati s Bluetooth 100M Universal Wireless Bluetooth Module Bluetooth 100M module is a simple to use Bluetooth module, command control through a simple UART Tx and Rx which are connected to other Bluetooth

More information

Exceptions and Interrupts ARM Cortex M3

Exceptions and Interrupts ARM Cortex M3 Exceptions and Interrupts ARM Cortex M3 ผศ.ดร. ส ร นทร ก ตต ธรก ล และ อ.สรย ทธ กลมกล อม 1 Introduction! Exception are events! They occur during the execution of the program! ARM exceptions! Exceptions

More information

Microcontroller basics

Microcontroller basics FYS3240 PC-based instrumentation and microcontrollers Microcontroller basics Spring 2017 Lecture #4 Bekkeng, 30.01.2017 Lab: AVR Studio Microcontrollers can be programmed using Assembly or C language In

More information

EECS 373 Design of Microprocessor-Based Systems

EECS 373 Design of Microprocessor-Based Systems EECS 7 Design of Microprocessor-Based Systems Matt Smith University of Michigan Serial buses, digital design Material taken from Brehob, Dutta, Le, Ramadas, Tikhonov & Mahal 1 Timer Program //Setup Timer

More information

Hierarchy of I/O Control Devices

Hierarchy of I/O Control Devices Hierarchy of I/O Control Devices 8155 I/O + Timer 2 Port (A,B), No Bidirectional HS mode (C) 4 mode timer 8253/54 Timer 6 mode timer 8255 I/O 2 Port (A,B) A is Bidirectional HS mode (C) Extra controls

More information

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used to connect devices such as microcontrollers, sensors,

More information

Basics of UART Communication

Basics of UART Communication Basics of UART Communication From: Circuit Basics UART stands for Universal Asynchronous Receiver/Transmitter. It s not a communication protocol like SPI and I2C, but a physical circuit in a microcontroller,

More information

18-349: Introduction to Embedded Real-Time Systems

18-349: Introduction to Embedded Real-Time Systems 18-349: Introduction to Embedded Real-Time Systems Embedded Real-Time Systems Lecture 5: Serial Buses Anthony Rowe Electrical and Computer Engineering Carnegie Mellon University Last Lecture ARM ASM Part

More information

17. Serial communication - I 2 C

17. Serial communication - I 2 C 7. Serial communication - I 2 C Two typical serial busses will be discussed and their use will be demonstrated in this and next chapter, these are I 2 C (Inter Integrated Circuit, IIC or I2C) and SPI (Serial

More information

19.1. Unit 19. Serial Communications

19.1. Unit 19. Serial Communications 9. Unit 9 Serial Communications 9.2 Serial Interfaces Embedded systems often use a serial interface to communicate with other devices. Serial implies that it sends or receives one bit at a time. µc Device

More information

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I. University of Texas at El Paso Electrical and Computer Engineering Department EE 3176 Laboratory for Microprocessors I Fall 2016 LAB 08 UART Communication Goals: Learn about UART Communication and the

More information

General-Purpose Input/Output. Textbook: Chapter 14 General-Purpose I/O programming

General-Purpose Input/Output. Textbook: Chapter 14 General-Purpose I/O programming General-Purpose Input/Output Textbook: Chapter 14 General-Purpose I/O programming 1 I/O devices May include digital and/or non-digital components. Typical digital interface to CPU is via addressable registers:

More information

EECS 373 Design of Microprocessor-Based Systems

EECS 373 Design of Microprocessor-Based Systems EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Timers Material taken from Dreslinski, Dutta, Le, Ramadas, Smith, Tikhonov & Mahal 1 Agenda A bit on timers Project overview

More information

Unit 19 - Serial Communications 19.1

Unit 19 - Serial Communications 19.1 Unit 19 - Serial Communications 19.1 19.2 Serial Interfaces Embedded systems often use a serial interface to communicate with other devices. Serial implies that it sends or receives one bit at a time.

More information

AN5123 Application note

AN5123 Application note Application note STSPIN32F0A - bootloader and USART protocol Introduction Cristiana Scaramel The STSPIN32F0A is a system-in-package providing an integrated solution suitable for driving three-phase BLDC

More information

Serial Communication. Simplex Half-Duplex Duplex

Serial Communication. Simplex Half-Duplex Duplex 1.5. I/O 128 Serial Communication Simplex Half-Duplex Duplex 129 Serial Communication Master-Slave Master Master-Multi-Slave Master Slave Slave Slave (Multi-)Master Multi-Slave Master Slave Slave Slave

More information

Lecture 10. Serial Communication

Lecture 10. Serial Communication Lecture 10 Serial Communication Serial Communication Introduction Serial communication buses Asynchronous and synchronous communication UART block diagram UART clock requirements Programming the UARTs

More information

TMS470R1x Serial Communication Interface (SCI) Reference Guide

TMS470R1x Serial Communication Interface (SCI) Reference Guide TMS470R1x Serial Communication Interface (SCI) Reference Guide Literature Number: SPNU196A September 2002 IMPORTANT NOTICE Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to

More information

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory Embedded Systems 3. Hardware Software Interface Lothar Thiele Computer Engineering and Networks Laboratory Do you Remember? 3 2 3 3 High Level Physical View 3 4 High Level Physical View 3 5 What you will

More information

Serial Communication

Serial Communication Serial Communication What is serial communication? Basic Serial port operation. Classification of serial communication. (UART,SPI,I2C) Serial port module in PIC16F887 IR Remote Controller Prepared By-

More information

FULL DUPLEX BIDIRECTIONAL UART COMMUNICATION BETWEEN PIC MICROCONTROLLERS

FULL DUPLEX BIDIRECTIONAL UART COMMUNICATION BETWEEN PIC MICROCONTROLLERS FULL DUPLEX BIDIRECTIONAL UART COMMUNICATION BETWEEN PIC MICROCONTROLLERS Dhineshkaarthi K., Sundar S., Vidhyapathi C. M. and Karthikeyan B. M. Tech, School of Electronics Engineering, VIT University,

More information

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465 Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465 Keywords: MAXQ, MAXQ610, UART, USART, serial, serial port APPLICATION NOTE 4465 Using the Serial Port on the

More information

27.7 SCI Control Registers

27.7 SCI Control Registers 27.7 SCI Control Registers These registers are accessible in 8-, 16-, and 32-bit reads or writes. The SCI is controlled and accessed through the registers listed in Table 27-3. Among the features that

More information

8051 Timers and Serial Port

8051 Timers and Serial Port 8051 Timers and Serial Port EE4380 Fall 2001 Class 10 Pari vallal Kannan Center for Integrated Circuits and Systems University of Texas at Dallas Timer: Mode 1 Operation (recap) 16 bit counter. Load the

More information

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation CoE3DJ4 Digital Systems Design Chapter 5: Serial Port Operation Serial port 8051 includes an on-chip serial port Hardware access to the port is through TXD and RXD (Port 3 bits 1 and 0) Serial port is

More information

AN2585 Application note

AN2585 Application note AN2585 Application note Application examples of the STM32F101xx and STM32F103xx core and system peripherals Introduction The STM32F10xxx is built around the latest Cortex -M3 core from ARM designed for

More information

Amarjeet Singh. January 30, 2012

Amarjeet Singh. January 30, 2012 Amarjeet Singh January 30, 2012 Website updated - https://sites.google.com/a/iiitd.ac.in/emsys2012/ Lecture slides, audio from last class Assignment-2 How many of you have already finished it? Final deadline

More information

Application Note, V1.0, Jul AP XC16x. Interfacing the XC16x Microcontroller to a Serial SPI EEPROM. Microcontrollers

Application Note, V1.0, Jul AP XC16x. Interfacing the XC16x Microcontroller to a Serial SPI EEPROM. Microcontrollers Application Note, V1.0, Jul. 2006 AP16095 XC16x Interfacing the XC16x Microcontroller to a Serial SPI EEPROM Microcontrollers Edition 2006-07-10 Published by Infineon Technologies AG 81726 München, Germany

More information

or between microcontrollers)

or between microcontrollers) : Communication Interfaces in Embedded Systems (e.g., to interface with sensors and actuators or between microcontrollers) Spring 2016 : Communication Interfaces in Embedded Systems Spring (e.g., 2016

More information

Laboratory 5 Communication Interfaces

Laboratory 5 Communication Interfaces Laboratory 5 Communication Interfaces Embedded electronics refers to the interconnection of circuits (micro-processors or other integrated circuits) with the goal of creating a unified system. In order

More information

STM32F030x4/x6/x8/xC Errata sheet

STM32F030x4/x6/x8/xC Errata sheet Errata sheet STM32F030x4/x6/x8/xC device limitations Silicon identification This document applies to the part numbers of STM32F030x4/x6/x8/xC devices listed in Table 1 and their silicon revisions shown

More information

Design with Microprocessors

Design with Microprocessors Design with Microprocessors Lecture 6 Interfaces for serial communication Year 3 CS Academic year 2017/2018 1 st Semester Lecturer: Radu Dănescu Serial communication modules on AVR MCUs Serial Peripheral

More information

BLE 1.4 SPI Driver Design Version 1.x (Draft)

BLE 1.4 SPI Driver Design Version 1.x (Draft) BLE 1.4 SPI Driver Design Version 1.x (Draft) Document Number: TBD TABLE OF CONTENTS 1. FUNCTIONAL OVERVIEW... 1 2. DEFINITIONS, ABBREVIATIONS, ACRONYMS... 2 3. REVISION HISTORY... 2 4. SPI INTERFACE...

More information

Serial Communication Prof. James L. Frankel Harvard University. Version of 2:30 PM 6-Oct-2015 Copyright 2015 James L. Frankel. All rights reserved.

Serial Communication Prof. James L. Frankel Harvard University. Version of 2:30 PM 6-Oct-2015 Copyright 2015 James L. Frankel. All rights reserved. Serial Communication Prof. James L. Frankel Harvard University Version of 2:30 PM 6-Oct-2015 Copyright 2015 James L. Frankel. All rights reserved. Overview of the Serial Protocol Simple protocol for communicating

More information

CHAPTER 5 REGISTER DESCRIPTIONS

CHAPTER 5 REGISTER DESCRIPTIONS USER S MANUAL 5 CHAPTER 5 REGISTER DESCRIPTIONS 5. INTRODUCTION This section describes the functions of the various bits in the registers of the SCC (Tables 5- and 5-2). Reserved bits are not used in this

More information

Serial Communications

Serial Communications April 2014 7 Serial Communications Objectives - To be familiar with the USART (RS-232) protocol. - To be able to transfer data from PIC-PC, PC-PIC and PIC-PIC. - To test serial communications with virtual

More information

Dallas Semiconductor DS1307 Real Time Clock. The DS 1307 is a real-time clock with 56 bytes of NV (nonvolatile)

Dallas Semiconductor DS1307 Real Time Clock. The DS 1307 is a real-time clock with 56 bytes of NV (nonvolatile) Using the MC9S12 IIC Bus with DS 1307 Real Time Clock DS1307 Data Sheet Asynchronous Serial Communications The MC9S12 Serial Communications Interface (SCI) Dallas Semiconductor DS1307 Real Time Clock The

More information

Digital Input and Output

Digital Input and Output Digital Input and Output Topics: Parallel Digital I/O Simple Input (example) Parallel I/O I/O Scheduling Techniques Programmed Interrupt Driven Direct Memory Access Serial I/O Asynchronous Synchronous

More information

UART Implementation Using the N2HET

UART Implementation Using the N2HET Application Report Lit. umber Month ear UART Implementation Using the 2HET Haixiao Weng MCU Safety Application ABSTRACT This application report describes how the Hercules 2HET peripheral can be used to

More information

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing Objectives Explain serial communication protocol Describe data transfer rate and bps rate Describe the main registers used by serial communication

More information

CprE 288 Introduction to Embedded Systems (UART Interface Overview)

CprE 288 Introduction to Embedded Systems (UART Interface Overview) CprE 288 Introduction to Embedded Systems (UART Interface Overview) Instructors: Dr. Phillip Jones http://class.ece.iastate.edu/cpre288 1 Announcement HW 4, Due Wed 6/13 Quiz 4 (15 min): Monday 6/11 at

More information

Asynchronous Data Transfer

Asynchronous Data Transfer Asynchronous Data Transfer In asynchronous data transfer, there is no clock line between the two devices Both devices use internal clocks with the same frequency Both devices agree on how many data bits

More information

Interfacing Techniques in Embedded Systems

Interfacing Techniques in Embedded Systems Interfacing Techniques in Embedded Systems Hassan M. Bayram Training & Development Department training@uruktech.com www.uruktech.com Introduction Serial and Parallel Communication Serial Vs. Parallel Asynchronous

More information

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI Laboratory Lesson 1: - Introduction to System Workbench for STM32 - Programming and debugging Prof. Luca Benini

More information

Features 2.4 GHz Carrier Frequency RS232 UART interface with variable baud rate Input supply voltage: 5V to 12V 255 possible Channels frequencies (0 to 255) Programmable Device Address (255 per channel)

More information

HZX N03 Bluetooth 4.0 Low Energy Module Datasheet

HZX N03 Bluetooth 4.0 Low Energy Module Datasheet HZX-51822-16N03 Bluetooth 4.0 Low Energy Module Datasheet SHEN ZHEN HUAZHIXIN TECHNOLOGY LTD 2017.7 NAME : Bluetooth 4.0 Low Energy Module MODEL NO. : HZX-51822-16N03 VERSION : V1.0 1.Revision History

More information

A B C D E F 0480 FE B F5 3B FC F3 E 1A 1D 2A 2D 3A 3D 4A 4D 5A 5D 6A 6D 7A 7D

A B C D E F 0480 FE B F5 3B FC F3 E 1A 1D 2A 2D 3A 3D 4A 4D 5A 5D 6A 6D 7A 7D What's on the 9S12 bus as it executes a program The 9S12 Serial Communications Interface 9S12 Serial Communications Interface (SCI) Block Guide V02.05 Huang, Sections 9.2-9.6 Consider a 9S12 executing

More information

HCS12 Serial Communications Interface (SCI) Block Guide V02.06

HCS12 Serial Communications Interface (SCI) Block Guide V02.06 DOCUMENT NUMBER S12SCIV2/D HCS12 Serial Communications Interface (SCI) Block Guide V02.06 Original Release Date: June 4, 1999 Revised: Oct 10, 2001 Motorola, Inc. Motorola reserves the right to make changes

More information

Module Introduction. PURPOSE: The intent of this module, is to explain several of the important features of Freescale s i.mx1 applications processor.

Module Introduction. PURPOSE: The intent of this module, is to explain several of the important features of Freescale s i.mx1 applications processor. Module Introduction PURPOSE: The intent of this module, is to explain several of the important features of Freescale s i.mx1 applications processor. OBJECTIVES: - Describe the features and functions of

More information

Table 1. Device summary. Table 2. Device variants. Device marking (1) STM32F070x6 A 0x1000 STM32F070xB Y or 1 0x2001

Table 1. Device summary. Table 2. Device variants. Device marking (1) STM32F070x6 A 0x1000 STM32F070xB Y or 1 0x2001 Errata sheet STM32F070x6/xB device errata Applicability This document applies to the part numbers of STM32F070x6/xB devices listed in Table 1 and their variants shown in Table 2. Section 1 gives a summary

More information

To be familiar with the USART (RS-232) protocol. To be familiar with one type of internal storage system in PIC (EEPROM).

To be familiar with the USART (RS-232) protocol. To be familiar with one type of internal storage system in PIC (EEPROM). Lab # 6 Serial communications & EEPROM Objectives To be familiar with the USART (RS-232) protocol. To be familiar with one type of internal storage system in PIC (EEPROM). Serial Communications Serial

More information

UNIT IV SERIAL COMMUNICATIONS

UNIT IV SERIAL COMMUNICATIONS UNIT IV SERIAL COMMUNICATIONS Serial channels are the main form of communications used in digital systems nowadays. Diverse forms of serial communication formats and protocols can be found in applications

More information

Am186ER/Am188ER AMD continues 16-bit innovation

Am186ER/Am188ER AMD continues 16-bit innovation Am186ER/Am188ER AMD continues 16-bit innovation 386-Class Performance, Enhanced System Integration, and Built-in SRAM Am186ER and Am188ER Am186 System Evolution 80C186 Based 3.37 MIP System Am186EM Based

More information

DN120 DeviceNet Gateway User Manual

DN120 DeviceNet Gateway User Manual DN120 DeviceNet Gateway User Manual DN120 PN 84-210010 Rev A Table of Contents CHAPTER 1 OVERVIEW... 4 CHAPTER 2 INSTALLATION... 5 MOUNTING... 5 WIRING... 6 DeviceNet Interface... 6 Serial Channel Interface...

More information

Serial Communication with PIC16F877A

Serial Communication with PIC16F877A Serial Communication with PIC16F877A In this tutorial we are going to discuss the serial/uart communication using PIC16F877A. PIC16F877A comes with inbuilt USART which can be used for Synchronous/Asynchronous

More information