Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Legacy microcontrollers Forum Discussions

Not applicable
I am using M430F2618T as a slave and Cyclone II fpga as a master in SPI data transfer. just for the purpose of testing, I want to transfer a square wave (MOSI signal) to microcontroller and get the same signal back as (MISO signal) at fpga. Here is the code for a microcontroller. Though I am able to get MOSI signal at microcontroller, I am not able to get MISO signal back at the fpga. Please suggest ay changes to be made in the microcontroller code.

#include

void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;


// // it is not yet in SPI mode
P3SEL |= 0x31; // P3.5,4,0 option select
UCA0CTL1 = UCSWRST; // **Put state machine in reset**
UCA0CTL0 |= UCSYNC+UCMSB; //3-pin, 8-bit SPI slave
UCA0CTL0 &= ~UCMST;
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt


while (1)
{
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF;

}
}
0 Likes
1 Reply
Juergen
Employee
Employee
Hi Varun,

This is actually a Infineon Microcontroller Forum. However, the methods are almost the same for all micros.
To get a square wave across the data line you need to send either 0xAA or 0x55. On receiving you then re-transmit what you have received. In order to be synchronous, you should do this in an interrupt service routine. You are doing this in the while(1) loop but you have enabled a RX interrupt. Thats where you should put this: UCA0TXBUF = UCA0RXBUF;
No need to check if the TX buffer is ready because as you receive a byte, one byte is sent out. This is SPI (Synchronous Serial Interface), it is basically a shift register.

I can give you code for our micros and in fact our easy kits contain a whole lot of examples which would make it very easy for you to develop your project. We even have a free toolchain on the CD.



Hope this helps. Best Regards
Jurgen
0 Likes