Interface an 8-bit serial device using SPI. The control pin is interfaced to PT2
ID: 3677067 • Letter: I
Question
Interface an 8-bit serial device using SPI. The control pin is interfaced to PT2, and the clock and data signals are connected to the SPI. The control and clock signals are normally high. The SPI needs to clock data out on the falling edge of the clock. The clock and data are created by the real SPI, and the control signal is bit-banged. The maximum clock frequency is 1 MHz.
The microcontroller that I am using for this course is the MC9S12G family. I would like for some explanation on the answers so that I can learn from them myself, full points will be awarded to the user who can do so with the correct answer.
THE QUESTIONS ARE AS FOLLOWS:
a) Write a function that initializes the interface.
b) Write a function that outputs (transmits) one byte using the SPI port. First send eight bits of data. then make PT2 low, then make PT2 high again.
Thanks ahead of time to anyone who take the time to help.
Explanation / Answer
//C code for sending simple chaser LED display to the 74HC595 output #include #include #define SPI_PORT PORTB #define SPI_DDR DDRB #define SPI_CS PB2 unsigned char SPI_WriteRead(unsigned char dataout) { unsigned char datain; // Start transmission (MOSI) SPDR = dataout; // Wait for transmission complete while(!(SPSR & (1Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.