// receiver.c // Runs on LM3S1968 // 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" // Initialize receiver #define Ack (*((volatile unsigned long *)0x40026004)) // PG0 #define Ready (*((volatile unsigned long *)0x40026008)) // PG1 #define Data (*((volatile unsigned long *)0x400253FC)) // Port F void Rcv_Init(void){ volatile unsigned long delay; SYSCTL_RCGC2_R |= 0x00000060; // activate Ports F and G delay = SYSCTL_RCGC2_R; // allow time to finish activating GPIO_PORTG_DIR_R |= 0x01; // PG0 is Ack out GPIO_PORTG_DIR_R &= ~0x02; // PG1 is Ready in GPIO_PORTG_DEN_R |= 0x03; // enable digital I/O on PG1-0 GPIO_PORTF_DIR_R = 0x00; // make PF7-0 input data GPIO_PORTF_DEN_R = 0xFF; // enable digital I/O on PF7-0 Ack = 1; } // Receiver // Handshaked // Receiver unsigned char Rcv_In(void){ unsigned char data; while(Ready == 0){}; // 2) Ack = 0; // 3) data = Data; // 4) Ack = 1; // 5) while(Ready){}; // 6) return(data); }