// transmitter.c // Runs on LM3S1968 // Used to test the transmitter.c driver // Valvano // August 5, 2011 /* This example accompanies the book "Embedded Systems: Real Time Interfacing to the Arm Cortex M3", ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2011 Example 4.4, Section 4.8, Programs 4.9, 4.10 and 4.11 Circuit Figure 4.34 Copyright 2011 by Jonathan W. Valvano, valvano@mail.utexas.edu You may use, edit, run or distribute this file as long as the above copyright notice remains THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. For more information about my classes, my research, and my books, see http://users.ece.utexas.edu/~valvano/ */ // Transmitter PG0 output Ready to receiver PG1 input // Receiver PG0 output Ack to transmitter PG1 input // Transmitter Port F output to receiver Port F input #include "lm3s1968.h" #define Ready (*((volatile unsigned long *)0x40026004)) // PG0 #define Ack (*((volatile unsigned long *)0x40026008)) // PG1 #define Data (*((volatile unsigned long *)0x400253FC)) // Port F // Initialize transmitter void Xmt_Init(void){ volatile unsigned long delay; SYSCTL_RCGC2_R |= 0x00000060; // activate Ports F and G delay = SYSCTL_RCGC2_R; // allow time to finish activating Ready = 0; GPIO_PORTG_DIR_R |= 0x01; // PG0 is Ready out GPIO_PORTG_DIR_R &= ~0x02; // PG1 is Ack in GPIO_PORTG_DEN_R |= 0x03; // enable digital I/O on PG1-0 GPIO_PORTF_DIR_R = 0xFF; // make PF7-0 out data GPIO_PORTF_DEN_R = 0xFF; // enable digital I/O on PF7-0 } // Transmitter // Handshaked void Xmt_Out(unsigned char data){ Data = data; // 1) Ready = 1; // 2) while(Ack){}; // 3) while(Ack == 0){}; // 5) Ready = 0; // 6) }