Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
47 views
62 pages
Communication Systems Using ARM
Uploaded by
phamleminhtien.shawn
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Communication Systems using ARM For Later
Download
Save
Save Communication Systems using ARM For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
47 views
62 pages
Communication Systems Using ARM
Uploaded by
phamleminhtien.shawn
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Communication Systems using ARM For Later
Carousel Previous
Carousel Next
Download
Save
Save Communication Systems using ARM For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 62
Search
Fullscreen
9. Communication Systems Chapter 9 objectives are to: + Introduce basic concepts of networks + Describe the controller area network (CAN) protocol + Present fundamentals and implementation of Bluetooth Low Energy (BLE) + Introduce Ethernet, Wireless, and the Internet of Things The goal of this chapter is to provide a brief introduction to communication systems. Communication theory is a richly developed discipline, and much of the communication theory is beyond the scope of this book. Nevertheless, the trend in embedded systems is to employ multiple intelligent devices, therefore the interconnection will be a strategic factor in the performance of the system. These devices will be developed by different manufacturers, thus the interconnection network must be flexible, robust, and reliable. Consequently, this chapter focuses on implementing communication systems appropriate for embedded systems. The components of an embedded system typically combined to solve a common objective, thus the nodes on the communication network will cooperate towards that shared goal. In particular, requirements of an embedded system, in general, involve relatively low bandwidth, static configuration, and a low probability of corrupted data. In Volume 2, networks designed with serial ports and ZigBee were presented. In this chapter we will discuss CAN, Bluetooth, and Ethernet.9.1. Fundamentals 9.1.1. The network A network is a collection of interfaces that share a physical medium and a data protocol. A network allows software tasks in one computer to communicate and synchronize with software tasks running on another computer. For an embedded system, the network provides a means for distributed computing. The topology of a network defines how the components are interconnected. Example topologies include rings, busses and multi-hop. Figure 9.1 shows a ring network of three microcontrollers. The advantage of this ring network is low cost and can be implemented on any microcontroller with a serial port. Notice that the microcontrollers need not be the same type or speed. The CAN network, presented in Section 9.2, is an example of a multi-drop bus. The ZigBee wireless network described in Volume 2 is a multi-hop network (duplicated in Figure 9.2). Notice that there can be multiple paths with which to route packets. age po RO] urs ART | sPagq | TM AC UART Gna] + Gnd TxD | unr} 0 ic TM $320 aoa 2! noffno Figure 9.1. Asimple ring network with three nodes, linked using the serial ports.Str © PAN coordinatr C ster tee Full function device Cl Reduced function device Figure 9.2. ZigBee wireless networks communicate by hopping between nodes. In Chapter 11 of Volume 2, we considered networks with one or two layers. In this chapter, we will build on those ideas and introduce the concepts of networks with more layers and higher bandwidths. A communication network includes both the physical channel (hardware) and the logical procedures (software) that allow users or software processes to communicate with each other. The network provides the transfer of information as well as the mechanisms for process synchronization, It is convenient to visualize the network in a hierarchical fashion as shown in Figure 9.3. M érocontro ler? Frames Physical link Figure 9.3. Alayered approach to communication systems. Most networks provide an abstraction that hides low-level details from high-level operations. This abstraction is often described as layers. The International Standards Organization (ISO) defines a 7-layer model called the Open Systems Interconnection (OSI), as shown in Figure 9.4. It provides a standard way to classify network components and operations.“"h pplication layer""-~ “ Prosentation kayer~ Session layer “Transport ayer" “Network layers “Data link byer Physical layer"*="-~ Figure 9.4. The Open Systems Interconnection model has seven layers. The Physical layer includes connectors, bit formats, and a means to transfer energy. Examples include RS232, controller area network (CAN), modem V.35, T1, 10BASE-T, 100BASE-TX, DSL, and 802.11a/b/g/n PHY. The Data link layer includes error detection and control across a single link (single hop). Examples include 802.3 (Ethernet), 802.11a/b/gin MAC/LLC, PPP, and Token Ring. The Network layer defines end-to-end multi-hop data communication. The Transport layer provides connections and may optimize network resources. The Session layer provides services for end-user applications such as data grouping and check points. The Presentation layer includes data formats, transformation services. The Application layer provides an interface between network and end-user programs. Observation: Communication systems often specify bandwidth in total bits/sec, but the important parameter is the data transfer rate. Observation: Often the bandwidth is limited by the software and not the hardware channel. Many embedded systems require the communication of command or data information to other modules at either a near or a remote location. A full duplex channel allows data to transfer in both directions at the same time. Ethernet, SPI, and UART implement full duplex communication. In a half duplex system, data can transfer in both directions but only in one direction at a time. Half duplex is popular because it is less expensive and allows the addition of more devices on the channel without change to the existing nodes. CAN, I°C, and most wireless protocols implement half- duplex communication. A simplex channel allows data to flow in only one direction. Checkpoint 9.1: In which manner to most people communicate: simplex, half duplex or full duplex?9.1.2. Physical Channel Information, such as text, sound, pictures and movies, can be encoded in digital form and transmitted across a channel, as shown in Figure 9.5. Channel capacity is defined as the maximum information per second it can transmit. In order to improve the effective bandwidth many communication systems will compress the information at the source, transmit the compressed version, and then decompress the data at the destination. Compression essentially removes redundant information in such a way that the decompressed data is identical (lossless) or slightly altered but similar enough (lossy). For example, a 400 pixels/inch photo compressed using the JPEG algorithm will be 5 to 30 times smaller than the original. A guided medium focuses the transmission energy into a well-defined path, such as current flowing along copper wire of a twisted pair cable, or light traveling along a fiber optic cable. Conversely, an unguided medium has no focus, and the energy field diffuses as in propagates, such as sound or EM fields in air or water. In general, for communication to occur, the transmitter must encode information as energy, the channel must allow the energy to move from transmitter to receiver, and the receiver must decode the energy back into the information, see Figure 9.5. In an analog communication system, energy can vary continuously in amplitude and time. A digital communication signal exists at a finite number of energy levels for discrete amounts of time. Along the way, the energy may be lost due to attenuation. For example, a simple V=I*R voltage drop is in actuality a loss of energy as electrical energy converted to thermal energy. ‘A second example of attenuation is an RF cable splitter. For each splitter, there will be 50% attenuation, where half the energy goes left and the other half goes right through the splitter. Unguided media will have attenuation as the energy propagates in multiple directions. Attenuation causes the received energy to be lower in amplitude than the transmitted energy. A second problem is distortion. The transfer gain and phase in the channel may be function of frequency, time, or amplitude. Distortion causes the received energy to be different shape than the transmitted energy. A third problem is noise. The noise energy is combined with the information energy to create a new signal. White noise is an inherent or internally generated noise caused by thermal fluctuations. EM field noise is externally generated and is coupled or added into the system. Crosstalk is a problem where energy in one wire causes noise in an adjacent wire. We quantify noise with signal-to-noise ratio (SNR), which is the ratio of the information signal power to noise power. Ave swan)-10-bs, TSeemare)channel jee VY Wh ey “Nl Figure 9.5. Information is encoded as energy, and errors can occur during transmission. Checkpoint 9.2: Why do we measure SNR as power and not voltage? Checkpoint 9.3: Why do we always have a ratio of two signals whenever we use the log,, to calculate the amplitude of a signal? Observation: Whenever we use the log,, to calculate the amplitude of a signal, we multiply by 10 if we have a ratio of two power signals or energy signals, and we multiply by 20 if we have a ratio of two voltage signals or current signals. ‘We can make an interesting analogy between time and space. A communication system allows us transfer information from position A to position B. A digital storage system allows us transfer information from time A to time B. Many of the concepts (encoding/decoding information as energy, signal to noise ratio, error detection/correction, security, and compression) apply in an analogous manner to both types of systems. Checkpoint 9.4: We measure the performance of a communication system as bandwidth in bits/sec. What is the analogous performance measure of a digital storage system? Errors can occur when communicating through a channel with attenuation, distortion and added noise. If the receiver detects an error, it can send a negative acknowledgement so the transmitter will retransmit the data. The CAN, ZigBee, and Bluetooth protocols handle this detection-retransmission process automatically. Networks based on the UARTs could define and implement error detection. For example, we can add an additional bit to the serial frame for the purpose of detecting errors. With even parity, the sum of the data bits plus the parity bit will be an even number. The framing error in the UART can also be used to signify the data may be corrupted. The CAN network sends a longitudinal redundancy check, LRC, which is the exclusive or of the bytes in the frame. The ZigBee network adds a checksum, which is the sum of all the data. The Network Processor Interface (NPI) later in this chapter uses LRC. There are many ways to improve transmission in the channel, reducing the probability of errors. The first design choice is the selection of the interface driver.For example, RS422 is less likely to exhibit errors than RS232. Of course having a driver will be more reliable than not having a driver. The second consideration is the cable. Proper shielding can improve SNR. For example, Cat6 Ethernet cables have a separator between the four pairs of twisted wire, which reduce the crosstalk between lines as compared to CatSe cable. If we can separate or eliminate the source of added noise, the SNR will improve. Reducing the distance and reducing the bandwidth often will reduce the probability of error. If we must transmit long distances, we can use a repeater, which accepts the input and retransmits the data again. Error correcting codes are beyond the scope of this book. However, we can present two simple error correcting codes. The first error correcting code involves sending three copies of each data. The receiver will compare the three versions received and majority vote will decide which value to use. A second error correcting code uses both parity and LRC, For example, assume we wished to send the message “Ciao”. Encoded as ASCII characters the data are $43, $69, $61, and $GF. The first step is to display the binary data in 2-D. Byte | Byte | Byte | Byte 0 1 2 3 Bit 7 |0 0 0 0 Bit6 | 1 1 i 1 Bit5 |0 1 1 1 Bit4 |0 0 0 0 Bit3 |0 1 0 1 Bit 2 |0 0 0 1 Bit |1 0 0 1 BitO | 1 1 1 1 The second step is to add an even parity to each byte and add a LRC at the end. Byte [Byte [Byte |Byte |LRC o |: i233 Parity[1 [0 |i [0 Jo Bit? [o [o [o |[o |o Bié [1 [1 |i [1 [o Bits [0 [1 1 1 1 Bit4 [oO [o |o [o |o Bi3 fo [1 |o [1 |o Bit2 [0 [o [o [1 1 Bil [1 [o |o [1 |o Bito [1 1 1 1 |o Notice that the even parity is the exclusive OR of each bit in the vertical column andthe LRC is the exclusive OR of each bit in the horizontal row. The parity bit for the LRC (or the LRC bit for the parity) will be the exclusive OR of all the data bits. Now, if any one bit in this 9-row by 5-column matrix is flipped, we can determine which byte is in error by the parity and which bit is in error by the LRC. Rather than asking for retransmission, we simply correct the error. These are very simple error correcting codes, but they illustrate that we can send more bits than the minimum and use those extra bits in a creative way to either detect or correct errors. RS422, RS485, Ethernet, and CAN are high-speed communication channels. This means the bandwidth and slew rate on the signals are higher than RS232. There is a correspondence between rise time (¢) of a digital signal and equivalent sinusoidal frequency (f). The derivative of A'sin(2nft) is 2nf'A:cos(2nft). The maximum slew rate of this sinusoid is 2nfA. Approximating the slew rate as A/t, we get a correspondence between f and ¢ Fut For example, if the rise time is 5 ns, the equivalent frequency is 200 MHz. Notice that this equivalent frequency is independent of baud rate. So even at 1000 bits/sec, if the rise time is 5 ns, then the signal has a strong 200 MHz frequency component! To deal with this issue, the RS232 protocol limits the slew rate to a maximum of 30V/ ps. This means it will take about 400 ns for a signal to rise from -6 to +6 V. Consequently, RS232 signals have frequency components less than 2 MHz. However, to transmit faster than RS232, the protocol must have faster rise times. Electrical signals travel at about 0.6 to 0.9 times the speed of light. This velocity factor (VF) is a property of the cable. For example, VF for RG-6/U coax cable is 0.75, whereas VF is only 0.66 for RG-58/U coax cable. Using the slower 0.66 estimate, the speed is v = 2-108 nvs. According to wave theory, the wavelength is | = w/f. Estimating the frequency from rise time, we get l=v *t In our example, a rise time of 5 ns is equivalent to a wavelength of about 1 m. As a rule of thumb, we will consider the channel as a transmission line if the length of the wire is greater than I/4, Another requirement is for the diameter of the wire to be much smaller than the wavelength. In a transmission line, the signals tavel down the wires as waves according to the wave equation, Analysis of the wave equation is outside the scope of this book. However, you need to know that when a wave meets a change in impedance, some of the energy will transmit (a good thing) and some of the energy will reflect (a bad thing). Reflections are essentially noise on the signal, and if large enough, they will cause bit errors in transmission, We can reduce the change in impedance by placing terminating resistors on both ends of a long high-speed cable, which are needed for both CAN and Ethernet. These resistors reduce reflections; hence they improve signal to noise ratio.9.1.3. Wireless Communication The details of exactly how wireless communication operates are beyond the scope of this book. Nevertheless, the interfacing techniques presented in this book are sufficient to implement wireless communication by selecting a wireless module and interfacing it to the microcontroller. In general, one considers bandwidth, distance, topology and security when designing a wireless link. Bandwidth is the fundamental performance measure for a communication system. In this book, we define bandwidth of the system as the information transfer rate. However, when characterizing the physical channel, bandwidth can have many definitions. In general, the bandwidth of a channel is the range of frequencies passed by the channel (Communication Networks by Leon-Garcia). Let G,(f) be the gain versus frequency of the channel. When considering EM fields transmitted across space, we can define absohite bandwidth as the frequency interval that contains all of the signal’s frequencies. Half-power bandwidth is the interval between frequencies at which G,(f) has dropped to half power (-3dB). Let f, be the carrier frequency, and P, be the total signal power over all frequencies. The equivalent rectangular bandwidth is P/G,(f,. The null-to-null bandwidth is the frequency interval between first two nulls of Gf). The FCC defines fractional power containment bandwidth as. the bandwidth with 0.5% of signal power above and below the band. The bounded power spectral density is the band defined so that everywhere outside G,(f) must have fallen to a given level. The purpose of this list is to demonstrate to the reader that, when quoting performance data, we must give both definition of the parameter and the data. If we know the channel bandwidth W in Hz and the SNR, we can use the Shannon-Hartley Channel Capacity Theorem to estimate the maximum data transfer rate C in bits/s: C= W*log,(1 + SNR) For example, consider a telephone line with a bandwidth W of 3.4 kHz and SNR of 38 dB. The dimensionless SNR = 10° = 6310. Using the Channel Capacity Theorem, we calculate C = 3.4 kHz * log,(1 + 6310) = 43 kbits/s. 9.1.4. Radio Figure 9.6 shows a rough image of various electromagnetic waves that exist from radio waves to gamma rays. Visible light constitutes a very small fraction, ranging from 430-770 THz. Bluetooth. ZigBee, and WiFi use an even narrower range from 2.40 to 2.48 GHz, which exists in the microwave spectrum.3kHz 3MHz 3GHz 3THZ S3PHz 3EHz 300 EH: Radio _-[M erow ave [infrared [lll uv ravs| x revs |_Ganmaravs Broadcast” GPS ; Qtr Vv Babe light Sone Wifi celbhones cellbhones BLE Figure 9.6. Bluetooth communication occurs in the microwave band at about 2.4 GHz. Table 9.1 shows some general descriptions of the three major communication standards operating in this 2.4 GHz band. Standard Description WiFi Up to 600 Mbits/sec Fixed wide frequency channels Requires lots of power Support for 2.4 and 5 GHz channels Extensive security features Bluetooth/BLE | Very low power BT up to 2 Mbps Massive deployed base Frequency hopping Good performance in congested/noisy environment Ease of use, no roaming ZigBee ‘Very low power Fixed channels Complex mesh network 250 kbps bandwidth Table 9.1. Comparison between Wi-Fi, Bluetooth, and ZigBee. Bluetooth LE could use any of the 40 narrow bands (LL 0 to 39) at 2.4 GHz; these bands are drawn as bumps in Figure 9.7. This figure also shows the WiFi channels, which exist as three wide bands of frequencies, called channel 1, 6 and 11. Because BLE coexists with regular Bluetooth and WiFi, BLE will avoid the frequencies used by other communication devices. LL channels 37, 38 and 39 are used to advertise, and LL channels 9-10, 21-23 and 33-36 are used for BLE communication. BLE has good performance in congested/noisy environments because it can hop from one frequency to another. Frequency Hopping Spread Spectrum (FHSS) rapidly switches the carrier among many frequency channels, using a pseudorandom sequence known to both transmitter and receiver. This way, interference will only affect some but not all communication.PRAMAAAGHRRS Figure 9.7. The 2.4 GHz spectrum is divided into 40 narrow bands, numbered LL 0 to 39. Each band is +1 MHz. Figure 9.8 illustrated the inverted F shape of the 2.4 GHz antenna used on the CC2650 LaunchPad. For more information on antenna layout, see http://www.ti.conylitv/an/swra351a/swra351a.pdf | 50-ohm feed point Figure 9.8. One possible layout of the 2.4 GHz antenna.9.2. Controller Area Network (CAN) 9.2.1. The Fundamentals of CAN In this section, we will design and implement a Controller Area Network (CAN). CAN is a high-integrity serial data communications bus that is used for real-time applications. It can operate at data rates of up to 1 Mbits/second, having excellent error detection and confinement capabilities. The CAN was originally developed by Robert Bosch for use in automobiles, and is now extensively used in industrial automation and control applications. The CAN protocol has been developed into an international standard for serial data communication, specifically the ISO 11989. Figure 9.9 shows the block diagram of a CAN system, which can have up to 112 nodes. There are four components of a CAN system. The first part is the CAN bus consisting of two wires (CANH, CANL) with 120-Q termination resistors on each end. The second part is the Transceiver, which handles the voltage levels and interfacing the separate receive (RxD) and transmit (TxD) signals onto the CAN bus. The third part is the CAN controller, which is hardware built into the microcontroller, and it handles message timing, priority, error detection, and retransmission. The last part is software that handles the high-level functions of generating data to transmit and processing data received from other nodes. : Transceiver | Transceiver | Transceiver] oe | | ee = Ss esl |Prer| |) | peg} Peer Se] Pras ‘a (ran ai Tem | Pare Figure 9.9. Block Diagram of a TM4C-Based CAN communication system Each node consists of a microcontroller (with an internal CAN controller), and a transceiver that interfaces the CAN controller to the CAN bus. A transceiver is a device capable of transmitting and receiving on the same channel. The CAN is based on the “broadcast communication mechanism’, which follows a message-based transmission protocol rather than an address-based protocol. The CAN provides twocommunication services: the sending of a message (data frame transmission) and the requesting of a message (remote transmission request). All other services such as error signaling, automatic retransmission of erroneous frames are user-transparent, which implies that the CAN interface automatically performs these functions. Both the TM4C123 and the TM4C1294 have two CAN devices. However, the MSP432 does not have a CAN interface. The physical channel consists of two wires containing in differential mode one digital logic bit. Because multiple outputs are connected together, there must be a mechanism to resolve simultaneous requests for transmission. In a manner similar to open collector logic, there are dominant and recessive states on the transmitter, as shown in Figure 9.10. The outputs follow a wired-and mechanism in such a way that if one or more nodes are sending a dominant state, it will override any nodes attempting to send a recessive state. Tine Figure 9.10. Voltage specifications for the recessive and dominant states. Checkpoint 9.5: What are the dominant and recessive states in open collector logic? The CAN transceiver is a high-speed, fault-tolerant device that serves as the interface between a CAN protocol controller (located in the microcontroller) and the physical bus. The transceiver is capable of driving the large current needed for the CAN bus and has electrical protection against defective stations. Typically, each CAN node must have a device to convert the digital signals generated by a CAN controller to signals suitable for transmission over the bus cabling. The transceiver also provides a buffer between the CAN controller and the high-voltage spikes than can be generated on the CAN bus by outside sources. Examples of CAN transceiver chips include the Texas Instruments SN6SHVD1050D, AMIS-30660 high speed CAN tansceiver, ST Microelectronics L9615 tansceiver, Philips Semiconductors AN96116 transceiver, and the Microchip MCP2551 transceiver. These transceivers have similar characteristics and would be equally suitable for implementing a CAN system. Ina CAN system, messages are identified by their contents rather by addresses. Each message sent on the bus has a unique identifier, which defines both the content and the priority of the message. This feature is especially important when several stations compete for bus access, a process called bus arbitration. As a result of the content- oriented addressing scheme, a high degree of system and configuration flexibility is achieved. It is easy to add stations to an existing CAN network. Four message types or frames can be sent on a CAN bus. These include the Data Frame, the Remote Frame, the Error Frame, and the Overload Frame. Thissection will focus on the Data Frame, where the parts in standard format are shown in Figure 9.11. The Arbitration Field determines the priority of the message when two or more nodes are contending for the bus. For the Standard CAN 2.0A, it consists of an 11-bit identifier. For the Extended CAN 2.0B, there is a 29-bit Identifier. The identifier defines the type of data. The Control Field contains the DLC, which specifies the number of data bytes. The Data Field contains zero to eight bytes of data. The CRC Field contains a 15-bit checksum used for error detection. Any CAN controller that has been able to correctly receive this message sends an Acknowledgement bit at the end of each message. This bit is stored in the Acknowledge slot in the CAN data frame. The transmitter checks for the presence of this bit and if no acknowledge is received, the message is retransmitted. To transmit a message, the software must set the 11-bit Identifier, set the 4-bit DLC, and give the 0 to 8 bytes of data. The receivers can define filters on the identifier field, so only certain message types will be accepted. When a message is received the software can read the identifier, length, and data. The Intermission Frame Space (IFS) separates one frame from the next. There are two factors that affect the number of bits in a CAN message frame. The ID (11 or 29 bits) and the Data fields (0, 8, 16, 24, 32, 40, 48, 56, or 64 bits) have variable length. The remaining components (36 bits) of the frame have fixed length including SOF (1), RTR (1), IDE/rl (1), r0 (1), DLC (4), CRC (15), and ACK/EOF/intermission (13). For example, a Standard CAN 2.0A frame with two data bytes has 11+16+36 = 63 bits, Similarly, an Extended CAN 2.0B frame with four data bytes has 29+32+36 = 97 bits. If a long sequence of 0’s or a long sequence of 1’s is being transferred, the data line will be devoid of edges that the receiver needs to synchronize its clock to the transmitter. In this case, measures must be taken to ensure that the maximum permissible interval between two signal edges is not exceeded. Bit Stuffing can be utilized by inserting a complementary bit after five bits of equal value. Some CAN systems add stuff bits, where the number of stuff bits depends on the data transmitted. Assuming n is the number of data bytes (0 to 8), CAN 2.0A may add 3+n stuff bits and a CAN 2.0B may add 5+n stuff bits. Of course, the receiver has to un-stuff these bits to obtain the original data. Message F rane onkol i, Daly field i 9RO feyiack i EOF [israel | sr—t amt ttn Dotinite—t f t—octnive Set DEA Figure 9.11. CAN Standard Format Data Frame. The urgency of messages to be transmitted over the CAN network can vary greatly in a real-time system. Typically, there are one or two activities that require hightransmission rates or quick responses. Both bandwidth and response time are affected by message priority. Low priority messages may have to wait for the bus to be idle. There are two priorities occurring as the CANs transmit messages. The first priority is the 11-bit identifier, which is used by all the CAN controllers wishing to transmit a message on the bus. Message identifiers are specified during system design and cannot be altered dynamically. The 11-bit identifier with the lowest binary number has the highest priority. In order to resolve a bus access conflict, each node in the network observes the bus level bit by bit, a process known as bit-wise arbitration. In accordance with the wired-and-mechanism, the dominant state overwrites the recessive state. All nodes with recessive transmission but dominant observation immediately lose the competition for bus access and become receivers of the message with the higher priority. They do not attempt transmission until the bus is available again. Transmission requests are hence handled according to their importance for the system as a whole. The second priority occurs locally, within each CAN node. When a node has multiple messages ready to be sent, it will send the highest priority messages first. Observation: It is confusing when designing systems that use a sophisticated VO. interface like the CAN to understand the difference between those activities automatically handled by the CAN hardware module and those activities your software must perform. The solution to this problem is to look at software examples to see exactly the kinds of tasks your software must perform. 9.2.2. Texas Instruments TM4C CAN A device driver for the CAN network is divided into three components: initialization, transmission, and reception. There is a CAN driver available in TivaWare®. In this section, we will use this driver to develop a simple system that exchanges 4-byte messages between two microcontrollers. Each node generates an interrupt when they receive a CAN message, and the interrupt handler dumps the data either into a mailbox. In this example, the transmission doesn’t block, just returns a failure if it can’t put, so it will not block or spin. This example was written using the TivaWare® driverlib library. Figure 9.12 shows the data flow. There are two IDs used in this example: #define RCV_ID 2 #define XMT_ID 4 The CAN ID numbers must be reversed on the other microcontroller. Otherwise, the software functions on the two nodes are identical.CAN i —— bus CAND SendD at { Eno oon ade Sh - ‘Nonb bck I TM 40123 [sw tc [-+CCAN0_SendD at ne LeD CANO_Getl ail Coy Wooné bck Figure 9.12. Data flow for a simple CAN network. CAN Transmission uses busy-wait synchronization. However, receiving messages is interrupt driven, and data is passed from the ISR to the user application using a simple mailbox: uint8_t static RCVData[4]; int static MailFlag;_// set when new data arrives The TM4C CAN receiver supports up to 32 message objects. Each message to be sent occupies a unique message object in the 32-object memory of the CAN controller and each receive object matches one of the transmit objects, just on the opposite board. Although this example has only two message objects it could easily be extended to up to 32 objects, but not beyond 32. In this code there are two message objects; the transmission object on one is connected to a receive object on the other. The following helper function sets up one of these 32 message objects, which can be a TX object or an RX object type. void static CANO_Setup_Message_Object( uint32_t MessageID, uint32_t MessageFlags, uint32_t MessageLength, uint8_t * MessageData, uint32_t ObjectID, tMsgObjType eMsgType){ tCANMsgObject xTempObject; xTempObject.ulMsgID = MessageID; // 11 or 29 bit ID xTempObject.ulMsgLen = MessageLength; xTempObject.pucMsgData = MessageData; xTempObject.ulFlags = MessageFlags; CANMessageSet(CANO_BASE, ObjectID, &xTempObject, eMsgType);} The initialization software first configures Port E bits 4,5 to be CANO. From Table 1.4 we see PE4 is CANORx, and PES is CANOTx. Next, it initializes the baudrate to 1,000,000 bps.It arms CAN interrupts on error and status change. A status change will occur when an incoming frame is successively __ received.The CANO_Setup_Message_Object function will configure one of the 32 message objects. Basically, it will set a filter to allow receive frames with this RCV_ID ID. An interrupt will be generated when receiving this type of frame, but other CAN traffic will be ignored. This function also specifies the expected size in bytes of the payload. Lastly, the CAN module is armed in the NVIC. Interrupts will be enabled in the main program after all devices are initialized. void CANO_Open(void){uint32_t volatile delay; MailFlag = false; SYSCTL_RCGCCAN_R [= 0x00000001; // CANO enable bit 0 SYSCTL_RCGCGPIO_R |= 0x00000010; // PortE enable bit 4 for(delay=0; delay<10; delay++){}; GPIO_PORTE_AFSEL_R |= 0x30; //PORTE AFSEL bits 5,4 GPIO_PORTE_PCTL_R = (GPIO_PORTE_PCTL_R&0xFFO0EFFF)|0x00880000; GPIO_PORTE_DEN_R GPIO_PORTE_DIR_R |= 0x20; CANInit(CANO_BASE); CANBitRateSet(CANO_BASE, 80000000, CAN_BITRATE); CANEnable(CANO_BASE); CANIntEnable(CANO_BASE,CAN_INT_MASTER|CAN_INT_ERROR|CAN_INT_STATUS CANO_Setup_Message_Object(RCV_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, RCV_ID, MSG_OBJ_TYPE_RX) NVIC_EN1_R = (1 << (INT_CAN return; } - 48)); // IntEnable(INT_CANO); Again, an interrupt is generated when a frame of the appropriate ID is received. The ISR will search the 32 possible message objects for the one that caused the interrupt. void CANO_Handler(void){uint8_t data[4]; int i; uint32_t ullntStatus,ulIDStatus; tCANMsgObject xTempMsgObject; xTempMsgObject.pucMsgData = data; ullntStatus = CANIntStatus(CANO_BASE, CAN_INT_STS_CAUSE); // cause? if(ullntStatus & CAN_INT_INTID_STATUS){ // receive? ulIDStatus = CANStatusGet(CAN0O_BASE, CAN_STS_NEWDAT); for(i = 0; i< 32; i++){ _// test every bit of the mask if( (0x1 << i) & ullDStatus){ // if active, get data CANMessageGet(CAN0_BASE, (i+1), &xTempMsgObject, true); if(xTempMsgObject.ulMsgID == RCV_ID){ RCVData[0] = data[0]; RCVData[1] = data[1]; RCVData[2] = data[2]; RCVData[3] = data[3]; MailFlag = true; // new mail } } }+ CANIntClear(CANO_BASE, ullntStatus); // acknowledge } When the user code wishes to receive a _—message, it calls CANO_GetMailNonBlock , which is a simple mailbox receiver. This function is nonblocking, meaning if there is no message it returns false. If there is a message, it copies the payload of 4 bytes and returns true. If the RTOS were available, the MailFlag could be replaces with a semaphore. The ISR would signal the semaphore on new data, and the user code could wait on that semaphore. int CANO_GetMailNonBlock(uint8_t data[4]){ if(MailFlag){ data[0] = RCVData[0]; data[1] = RCVData[1]; data[2] = RCVData[2]; data[3] = RCVData[3]; MailFlag = false; return true; return false; } int CANO_CheckMail(void){ return MailFlag; } When the user code wishes to transmit data it calls this function, which configures a new message object. This function will send 4 bytes of data to other microcontroller. void CANO_SendData(uint8_t data[4]){ CANO_Setup_Message_Object(XMT_ID,NULL,4,data,XMT_ID,MSG_OBJ_TYPE_TX); } The UserTask ISR periodically reads its switches and creates a transmit object. Because the transmission rate is slower than the network, the transmitter does not wait. It simply creates the message object (CANO_SendData ) and schedules it for transmission. When received by the other microcontroller an interrupt is generated and the data is put in a mailbox. The main program on the other microcontroller reads the mail and writes the data out to its LED. Data flows in both directions. Remember to reverse the XMT_ID RCV_ID values on the two microcontrollers. uint8_t XmtData[4]; uint8_t RevData[4]; uint32_t RevCount=0; uint8_t sequenceNum=0; void UserTask(void){ XmtData[0] = PF0<<1; //0 or 2 XmtDatal[1] = PF4>>2; //0 or 4 XmtData[2] = // unassigned fieldXmtData[3] = sequenceNum; // sequence count CANO_SendData(XmtData); sequenceNum++; } int main(void){ PLL_Init(Bus80MHz); // bus clock at 80 MHz SYSCTL_RCGCGPIO_R[- 0x20; _// activate port F while((SYSCTL_PRGPIO_R&0x20 ys GPIO_PORTF_LOCK_R = 0x4C4F434B; // unlock GPIO Port F GPIO_PORTF_CR_R = 0xFF; // allow changes to PF4-0 GPIO_PORTF_DIR_R = 0x01 // make PF3-1 output GPIO_PORTF_AFSEL_R = 0; // disable alt funct GPIO_PORTF_DEN_R = 0x1 // enable digital /O on PF4-0 GPIO_PORTF_PUR_R=0x11; _// enable pullup on inputs GPIO_PORTF_PCTL_R = 0x00000000; GPIO_PORTF_AMSEL_R = 0; // disable analog functionality on PF CANO_Open(); Timer3_Init(&UserTask, 1600000); // initialize timer3 (10 Hz) EnableInterrupts(); while(1){ if(CANO_GetMailNonBlock(RcvData)){ RevCount++; PF1 = RevDatal0]; PF2 = RevDatal1]; PF3 = RevCount; // heartbeat } } d Program 9.1. Very simple CAN network example. In this simple example, there is just one transmit ID type and one receive ID type, but you could rewrite the transmitter and receiver to allow multiple ID types. In this case, the message ID (11-bit ID) and the object ID (0 to 31) are the same. In general, there could be 2048 IDs, but in this example only the first 32 can be used. The transmit messages are sent without interrupts, but the receive messages will trigger an interrupt. It would take three steps to expand to more receive IDs. First, we would call CANO_Setup_Message_Object multiple times during initialization, once for each type of message we wish to receive (obviously, giving each a unique ID, up to 32). Second, for each possible ID, we would duplicate the if(xTempMsgObject.ulMsgIl .CV_ID){} test in the ISR to check if a desired message has been received. Third, each message ID would need its own mailbox or FIFO. This way the user tasks could be signaled when the appropriate data is available. Expanding the system to support more transmit message IDs is simple. We simple duplicate CANO_SendData function for each message ID we wish to send.9.3. Embedded Internet This section provides a brief introduction to the Internet as well as present low-level details of the Ethernet controller on a Tiva microcontroller. For an excellent description of the TCP/IP (Transmission Control Protocol/Internet Protocol) protocol the reader is referred to W. Richard Stevens, TCP/IP Illustrated, Volume _1: The Protocols. For a general description of the internet of things, see Vasseur and Dunkels, Interconnecting Smart Objects with IP. These two books provide good overviews of network technologies used for connecting devices. 9.3.1. Abstraction Ina manner similar to ZigBee, TCP/IP packets hop from one network to another as they travel from source to destination, see Figure 9.13. The network schedules communication and provides routing from source to destination. Communication channels such as USB and CAN have scheduling mechanisms to guarantee real-time performance. In particular, USB allows for prenegotiated bandwidth, so important data can be sent in real time. Because of the priority, important CAN messages will have bounded latency. TCP/IP although fast and reliable has no built-in guarantees of timing. Nevertheless, the use of TCP/IP is growing in the embedded world. Often TCP/IP is fast enough and reliable enough for embedded applications, even if response time is uncertain. FIP FTP aa Hog P Router E there Figure 9.13. Packets on the internet hop from one network to another. When faced with a complex problem, one could develop a solution on one powerful and centralized computer system. Alternatively a distributed solution could be employed using multiple computers connected by a network. The processing elements in Figure 9.14 may be a powerful computer, a microcontroller, an ASIC, or a smart sensor/actuator. Another name given for an embedded system connected to the internet is smart object. Smart objects include sensors to collect data, processing todetect events and make decisions, and actuators to manipulate the local environment. Table 9.2 lists some existing applications and the things they sense or control. There are many reasons to consider a distributed solution (network) over a centralized solution. Often multiple simple microcontrollers can provide a higher performance at lower cost compared to one computer powerful enough to run the entire system. Some embedded applications require inpuVoutput activities that are physically distributed. For real-time operation there may not be enough time to allow communication between a remote sensor and a central computer. Another advantage of distributed system is improved debugging, For example, we could use one node in a network to monitor and debug the others. Often, we do not know the level of complexity of our problem at design time. Similarly, over time the complexity may increase or decrease. A distributed system can often be deployed that can be scaled. For example, as the complexity increases more nodes can be added, and if the complexity were to decrease nodes could be removed. Industrial Automation —_ Factories, machines, shipping Environment Weather, pollution, public safety Smart Grid Electric power, energy delivery Smart Cities Transportation, hazards, public services Social Networks Ideas, politics, sales, and communication Home Networks Lighting, heat, security, information Building Networks Energy, hazards, security, maintenance Structural Monitors Bridges, roads, building Health Care Heart function, medical data, remote care Law enforcement —_Crime, public safety Table 9.2. Applications of smart objects. artob ect MU icrocontro lier] Sensor ( wn artob pot W icrocontro lier) [A ctuator| ( m artob ect Microcontroller) *-] Sensor ( Figure 9.14. The internet of things places input, output and processing at multiple locations connected together over the internet.The TCP/IP model of the Internet does not adhere to such a strict layered structure, but does recognize four broad layers: scope of the software application; the end-to- end transport connection; the internetworking range; and the direct links as shown on the right of Figure 9.15. Examples of applications include Telnet, FTP (File Transfer Protocol), and SMTP (Simple Mail Transfer Protocol). Examples of transport include TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). TCP provides reliable, ordered delivery of data from a software task on one computer to another software task running on another computer. For applications that do not require reliable data stream service UDP can be used. UDP provides a datagram service that emphasizes reduced latency over reliability. Examples of network include IP (Internet Protocol), ICMP (Internet Control Message Protocol) and IGMP (Internet Group Management Protocol). Ethernet is the physical link explored later in this section. In this section we will develop projects at the application layer. The communication of bits happens at the physical layer, frames at the data link layer, packets or datagrams at the network layer, segments at the transport layer, and messages at the application layer. ost TOPAP App lication Exam pes i Application | 4 TTP Tehot Presentation’ OH TBEIP i Session rep Transport Transport ~ ; TCP. UDP New ork Intemet IP ICMP. GMP i Data link ali ; - Gonrolphyscal| £7met wif Physical Layers Figure 9.15. The TCP/IP model has four layers. 9.3.2. Message Protocols The layered format can be seen in the message packet formats, as overviewed in Figure 9.16, At the lowest level are Ethernet frames, which contain a header, 46 to 1500 bytes of payload, and a trailer. The header includes address, type and length information. If the there is less than 46 bytes of Ethernet data, zeros are added (padding) to make the Ethernet payload at least 46 bytes. The trailer includes error checking (CRC). At the IP level, packets include a header and payload. The header of an IP packet includes a 32-bit destination IP address, typically shown as four 8-bit numbers (e.g, 176.31.244.1). Some of these IP addresses are reserved for communicating within nodes on a local network. The Domain Name System (DNS)host can be used to translate domain names to IP addresses. Computers that communicate only with each other via TCP/IP, but are not connected to the Internet, need not have globally unique IP addresses. IP addresses for private networks are listed in Table 9.3, These IP addresses could be used for systems that use TCP/IP to communicate, but are not connected to the internet. Start End ‘Number of addresses 10.0.0.0 10.255.255.255, 2 172.16.0.0 172.31.255.255 2 192.168.0.0 192.168.255.255 _| 2° Table 9.3. Private IP addresses. Because of the growth of the internet, the 32-bit IP address (IPv4) is being replaced with a 128-bit address (IPv6), which will provide for about 3-10* addresses. User ata Application Apo! Fee: UserD ata TP TCP sanent | TCP | Application D ata header’ P P datgran Lie 1 | Application D ata JE hemet Ethemet | Ethemet | IP TCP | Application Dat | Ethemet fame Ubeader | header | header|“PPUPSPY 8? | trailer 22 20 20 4 bytes I 46 to 1500 bys" | Figure 9.16. Overview of message packets used at various layers. 9.3.3. Ethernet Physical Layer The goal of Ethernet is to provide reliable communication over an unreliable medium. The Ethernet physical layer has evolved over time and includes many physical media interfaces. Ethernet speed ranges over 2 orders of magnitude, The most common forms used are 10BASE-T, 100BASE-TX, and 1000BASE-T. All three utilize twisted pair cables and 8P8C modular connectors. They run at 10 Mbit/s, 100 Mbit/s, and 1 Gbit/s, respectively. Fiber optic variants of Ethernet offer high performance, electrical isolation and distance (tens of kilometers with someversions). In general, network protocol stack software will work similarly on all varieties. The left side of Figure 9.17 shows two processing elements connected with Ethernet. The transmitter of one element is connected to the receiver of the other. If more than two processing elements are connected to the same physical medium, then collisions could occur. One solution to reduce collisions is to use an Ethernet switch (right side of Figure 9.17). A een! A B ic D Figure 9.17. Ethernet has a bus-based topology. Hubs and switches allow multiple devices to exist on the same network. They differ in the way that they pass the network traffic that they receive. A hub repeats incoming frames to all nodes on the network. If there are a small number of nodes and the traffic is light, this simple approach is adequate. A switch learns the addresses of the nodes connected to it; this way, an incoming frame is sent only to the proper node. If there are a lot of nodes, this selective retransmission provides a significant improvement in performance over a hub. A router sits between two networks and passes frames from one network to another, see Figure 9.13. Packets from one element are sent to the appropriate destination. If a collision were to occur (sending packets to the same destination at the same time), then the switch will delay one packet to avoid the collision, From the viewpoint of the nodes, the network looks like a bus-based topology. For example, if processing element A wishes to send a packet to processing element C, it transmits the packet that is addressed to C onto the bus, and the C receives it. Table 9.4 shows the pin assignments in the 8-wire 568-B connectors. The 568-A connector has the transmit and receive pins reversed. These two connector configurations are similar to the data terminal equipment (DTE) and the data communication equipment (DCE) of RS232 described in Section 4.9 of Volume 2. When connecting a processing element to a switch, a 568-B connector is used on the processing element and a 568-A connector is used on the switch. This way a straight- through 8-wire cable can be used (Figure 9.18). When connecting two processing element to each other, both elements use 568-B connectors. For this situation the pairs 2 and 3 are reversed in the cable can be used (Figure 9.19 and Table 9.5). Pin Color Pair Description 1 white/orange | 2 ‘TxData + 2 orange 2 TxData - 3 white/green | 3 RecyData + 4 blue 1 Unused 5 white/blue | 1 ‘Unused 6 green 3 RecvData -
You might also like
CG Unit3
PDF
No ratings yet
CG Unit3
25 pages
CN UNIT I
PDF
No ratings yet
CN UNIT I
27 pages
اسس شبكات الحاسوب مرحلة 3
PDF
No ratings yet
اسس شبكات الحاسوب مرحلة 3
135 pages
Chapter1 Int. To Comm. System 2018
PDF
No ratings yet
Chapter1 Int. To Comm. System 2018
13 pages
COMPUTER NETWORKS Physical Layer
PDF
No ratings yet
COMPUTER NETWORKS Physical Layer
36 pages
Mobile Computing - I
PDF
No ratings yet
Mobile Computing - I
27 pages
COMPUTER SCIENCE 300 LEVEL BBRAINSTORMING CLASS - LASUSTECH.docx
PDF
No ratings yet
COMPUTER SCIENCE 300 LEVEL BBRAINSTORMING CLASS - LASUSTECH.docx
10 pages
Ee 706 Lec Notes
PDF
No ratings yet
Ee 706 Lec Notes
102 pages
Examples: Radio Broadcast T.V Internet Multicast Guided Missile
PDF
No ratings yet
Examples: Radio Broadcast T.V Internet Multicast Guided Missile
6 pages
Prof. Abdelshakour Abuzneid
PDF
No ratings yet
Prof. Abdelshakour Abuzneid
40 pages
Overview of Data Communication and Networking
PDF
No ratings yet
Overview of Data Communication and Networking
11 pages
Screenshot 2025-01-24 at 03.47.29
PDF
No ratings yet
Screenshot 2025-01-24 at 03.47.29
31 pages
Un Academy Ccna Note
PDF
No ratings yet
Un Academy Ccna Note
193 pages
Manchester 149-156
PDF
No ratings yet
Manchester 149-156
8 pages
DC Module1 1
PDF
No ratings yet
DC Module1 1
13 pages
Data and Digital Communications
PDF
No ratings yet
Data and Digital Communications
6 pages
Presentation 2
PDF
No ratings yet
Presentation 2
47 pages
Computer Network Notes
PDF
No ratings yet
Computer Network Notes
4 pages
6.Communication
PDF
No ratings yet
6.Communication
128 pages
Cs3591 Cn Unit 1 Notes (1)
PDF
No ratings yet
Cs3591 Cn Unit 1 Notes (1)
37 pages
Introduction WCN
PDF
No ratings yet
Introduction WCN
30 pages
Telecommunication: Basic Elements
PDF
No ratings yet
Telecommunication: Basic Elements
11 pages
NS3 Notes
PDF
No ratings yet
NS3 Notes
66 pages
2marks Computer Networks
PDF
No ratings yet
2marks Computer Networks
28 pages
Data Comm and Comp Networking Lecture Note
PDF
No ratings yet
Data Comm and Comp Networking Lecture Note
35 pages
Netviva
PDF
No ratings yet
Netviva
5 pages
EECS 307: Communication Systems: Week 1 Refik Caglar Kizilirmak Nazarbayev University
PDF
No ratings yet
EECS 307: Communication Systems: Week 1 Refik Caglar Kizilirmak Nazarbayev University
36 pages
CS3591 CN Unit 1 Notes-1
PDF
No ratings yet
CS3591 CN Unit 1 Notes-1
66 pages
Computer Networks - Unit II
PDF
No ratings yet
Computer Networks - Unit II
14 pages
Notes-Unit-1-CS3697
PDF
No ratings yet
Notes-Unit-1-CS3697
79 pages
Rahu Final
PDF
No ratings yet
Rahu Final
14 pages
Embedded System Communication
PDF
No ratings yet
Embedded System Communication
41 pages
Lecture 4 - Student Version
PDF
No ratings yet
Lecture 4 - Student Version
57 pages
Computer Network
PDF
No ratings yet
Computer Network
18 pages
Introduction To Wireless Communication and Transmission Fundamentals Dr. Arslan Shaukat
PDF
No ratings yet
Introduction To Wireless Communication and Transmission Fundamentals Dr. Arslan Shaukat
52 pages
Computer Networks: 7 Application 6 Presentation 5 Session 4 Transport 3 Network
PDF
No ratings yet
Computer Networks: 7 Application 6 Presentation 5 Session 4 Transport 3 Network
46 pages
Neworking PQ
PDF
No ratings yet
Neworking PQ
8 pages
Icit
PDF
No ratings yet
Icit
47 pages
Computer Networks Osi Model: Physical Layer Data Link Network
PDF
No ratings yet
Computer Networks Osi Model: Physical Layer Data Link Network
49 pages
CSE Final Solve
PDF
No ratings yet
CSE Final Solve
11 pages
The Physical Layer
PDF
No ratings yet
The Physical Layer
18 pages
Cheat Sheet
PDF
No ratings yet
Cheat Sheet
3 pages
Block-3 Important Questions
PDF
No ratings yet
Block-3 Important Questions
15 pages
EC3401 Networks and Security Lecture Notes 1
PDF
No ratings yet
EC3401 Networks and Security Lecture Notes 1
113 pages
Cse211-Computer Network AY-2019-2020 Semester-1 August-December
PDF
No ratings yet
Cse211-Computer Network AY-2019-2020 Semester-1 August-December
129 pages
Lec4_Serial Commu Pro (4)
PDF
No ratings yet
Lec4_Serial Commu Pro (4)
70 pages
Industrial Data Comunication Fundamental
PDF
No ratings yet
Industrial Data Comunication Fundamental
7 pages
Varna Free University: Computer Networks Osi Model: Physical Layer Data Link Network
PDF
No ratings yet
Varna Free University: Computer Networks Osi Model: Physical Layer Data Link Network
46 pages
Company Background and Its Organisational Structure (Tec)
PDF
No ratings yet
Company Background and Its Organisational Structure (Tec)
39 pages
CCN Preps
PDF
No ratings yet
CCN Preps
10 pages
CCN 5 Marks
PDF
No ratings yet
CCN 5 Marks
7 pages
CN Full Notes (Module1 and Module 2)
PDF
No ratings yet
CN Full Notes (Module1 and Module 2)
239 pages
Computer Networking
PDF
No ratings yet
Computer Networking
62 pages
Data Transmission: Presented By: Kristina Westin Andy Noll Jen Stoe
PDF
No ratings yet
Data Transmission: Presented By: Kristina Westin Andy Noll Jen Stoe
35 pages
Networking in CAN Technology
PDF
No ratings yet
Networking in CAN Technology
12 pages
Cna Unit I
PDF
No ratings yet
Cna Unit I
43 pages