SPI function on AVR START

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to ping a slave. With the following code.


uint8_t Read25r3911b (uint8_t commandaddress)
{   uint8_t data;
	uint8_t TEMP;
	TEMP=commandaddress;
	data=0xFF;
	PORTC_set_pin_level(3,low);
	
	SPI_0_write_block(&TEMP,1);
     while ((SPI0.INTFLAGS & SPI_RXCIF_bm) == 0) ;

  //  while (SPI_0_status_done());
	
      
	    
    //    SPI0.INTFLAGS &= ~(1<<INTERUPT_FLAG);
     	//PORTC_set_pin_level(3,high);
	SPI_0_read_block(&data,1);
	while ((SPI0.INTFLAGS & SPI_RXCIF_bm) == 0) ;
	

		return data;
}

The first part of the code tells the slave to give a value in the following byte.  The issue is that read block is not reading the value.   

Attachment(s): 

Daniel Morley

Last Edited: Mon. Dec 9, 2019 - 08:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

See Tip #1 for how to do that!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil I don't understand the message.   Could you clarify.   Is there something incorrect in the way I posted the question. 

 

 

Daniel Morley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It would be helpful if you would post the picture in your post.  Tip #1 in Andys signature has a link on how to do this.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Daniel Morley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As you can see the function SPI_0_write_block is working by sending the code 43 to the slave.   This is a read  and address of the register.   It's value is 8 by default.   The read function does not return this value.

Daniel Morley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post your read function and teh associated screenshot of your analyser.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The code is the default created by AVR start.

 

void SPI_0_read_block(void *block, uint8_t size)
{
	SPI_0_desc.data   = (uint8_t *)block;
	SPI_0_desc.size   = size;
	SPI_0_desc.type   = SPI_READ;
	SPI_0_desc.status = SPI_BUSY;

	SPI0.DATA = 0;
}

 

Daniel Morley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely the Slave is returning 0x08 from the 0x00 write

 

Of course you will need to read the documentation for Start.   I suspect you are simply reading the response from the 0x43 write.   The next read will return the response from the 0x00 write.

 

I suggest that you initialise data with a unique value e.g 0x55.   Then you will see whether you are receiving 0xFF or 0x08.

 

What target device are you using?

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

uint8_t Read25r3911b (uint8_t commandaddress)
{   uint8_t data;
	uint8_t TEMP;
	TEMP=commandaddress;
	data=0xFF;
	PORTC_set_pin_level(3,low);
	
	SPI_0_write_block(&TEMP,1);
     while ((SPI0.INTFLAGS & SPI_RXCIF_bm) == 0) ;

  //  while (SPI_0_status_done());
	
      
	    
    //    SPI0.INTFLAGS &= ~(1<<INTERUPT_FLAG);
     	//PORTC_set_pin_level(3,high);
	SPI_0_read_block(&data,1);
	while ((SPI0.INTFLAGS & SPI_RXCIF_bm) == 0) ;
	

		return data;
}

Daniel Morley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The target device is a 25r3911 or a NFC board.   The byte 0x43 should return the register value on the next byte after the slave receives the command.   The 0xFF is just don't cares.   

Daniel Morley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

x-nucleo-nfc05a1 using a TINY416 as mcu spi master.

Daniel Morley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
See Tip #1 for how to do that!
I'll remind you again that folks using mobiles and tablets won't be seeing any "signature" so saying "see tip #1" will be largely meaningless if they can't see the #N's ! ;-)

 

(I'd maybe say "see tip #1 in my signature below (only visible on PC, not tablet/mobile)" or something similar perhaps?)