# SPI ATMEGA328P does not send back on MISO

I am using ATMega328P and programming in Atmel Studio 7 and I am trying to initialize the SPI. I initialize it and send some data, checked with the oscilloscope, the data is sending on MOSI line but I get nothing on MISO from the MFRC522 RFID sensor that is the slave.

I am working in master mode, this is the code:

void spi_masterinit()
{
DDRB = 0xEF; //initializare port
DDRB |= (1<<3)|(1<<5)|(1<<2); // MOSI , SCK OUTPUT ,SS
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);//prescaler 16 , Master mode  , SPI enable
DDRB &= ~(1<<4); //MISO INPUT
}

uint8_t  spi_mastertransmit( uint8_t data)
{
while(!(SPSR & (1<<SPIF)));  // wait for the flag SPIF to be 1
return SPDR; // return data
}


This is the code for init and transmit and this is the main:

int main(void)
{
uint8_t data = 0;
_delay_ms(50);
spi_masterinit();
_delay_ms(1000);
mfrc522_init();
_delay_ms(50);

while(1)
{
PORTB &= ~(1<<2); //cs active
spi_mastertransmit(data++);
PORTB |= (1<<2);
_delay_ms(1000); //disable cs
}
return 0;
}

• Please make an effort to format your post a little. :) I formatted your code but would be nice to post here text not in "chat format". – Duck Dodgers Jul 24 '19 at 9:23
• Welcome to the site. Please realise this is not a free design house, homework-answering service or an on-line technical encyclopedia, copied out to you on demand. People will help you take the next step if your question shows you've done as much as you possibly could on your own - which yours doesn't, I'm afraid. Please edit your question and greatly improve it. Show your work and findings so far in considerable detail with a schematic. The schematic editor here is a breeze to use. The better the quality of question, the better the quality of the answers you will attract. Again, a warm welcome – TonyM Jul 24 '19 at 12:21
• Consider starting with a known-good Arduino example for this combination to validate the hardware and gain some understanding of the needed operations. Then re-visit your custom bare-metal direct-to-registers solution informed by that. – Chris Stratton Jul 24 '19 at 16:18