Problems with ATXmega256 in a protocol like SPI

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

Hi all.

I've problem with ATXmga256A3U that I'm new.

I have done this before by ATmega8, ATmega328, ATmega128..., 8MHz, 16MHz, 20MHz

 

I've a board that only send data, like SPI protocol. In hi level of clock pulse, the data will be valuable.

I send values in sequence with 100ms. length of each value is 6ms.

 

When I receive each value and I want to process it, all bit of each value are 1. but when I make a loop and read lines (data & clock) and I set and reset the LED, the LED works correctly.

I write this program with IAR-AVR and Microchip Studio, Codevision-AVR and with 16MHz, 32MHz clock, but I receive incorrect value!!!

 

Please help me.

 

Thanks...

Last Edited: Fri. May 28, 2021 - 10:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


Welcome to AVRFreaks!

 

shahab_taheri wrote:
Please help me.

Well the crystal ball is in the shop for repair, perhaps, if you showed us your code a freak will jump in with a solution!

Have a great day!

 

Jim

PS: please use the "<>" code editor in the menu to copy/paste your code into!

edit add link to App Note xmega SPI how to use: https://www.microchip.com/wwwApp...

 

Most SPI slave devices (you did not say what yours is) will have a CS or /CS pin that enables and syncs data transfers between master and slave devices, you will need to designate a spare port pin on your xmega for this use, and configure it and drive it as needed, most slave SPI device expect a low level on the /CS pin to enable the slave to receive data, but some require a high level, see slave device datasheet for details.

Then connect it like this:

Follow example code as shown in app note to send/receive data, note data transfers in both direction at the same time!

 

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Wed. May 26, 2021 - 06:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear ki0bk, thanks for fast response.

 

Like SPI, not SPI.

#define _clk	    PORTC.IN & PIN0_bm
#define _data	    PORTC.IN & PIN1_bm

uint32_t Read (void)
{
	uint32_t Accumulator = 0;
	uint16_t Quietness = 0;

	while (Quietness++ < 1000)
	    if (!_clk)	Quietness = 0;

	for (uint8_t i = 0; i < 20; i++)
	{
	    while ( _clk);  // while ( _clk) _delay_us (5);
	    // LED = Low, Clock = Low
	    while (!_clk);  // while (!_clk) _delay_us (5);
	    // LED = Hi, Clock = Hi

            Accumulator <<= 1;

	    // Accumulator |= _data;
	    if (_data)	Accumulator |= 1;
	}

	return Accumulator;
}

The board generate clock and data, and ATXmega256A3U read these 2 lines.

 

Thanks.

Last Edited: Fri. May 28, 2021 - 10:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No one has a solution??????????

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

Solution to what, exactly?

 

You need to give some more details.

 

  • A proper specification of this "like SPI; not SPI" protocol.
    eg a timing diagram; schematic, etc
  • What is you code intended to do?
  • What is you code actually  doing?
  • What testing/investigation/debugging have you done to find out what's going on?
    eg, have you used an oscilloscope and/or logic analyser to see what's happening on the wires?

 

Do you have a known-good reference implementation of this protocol?

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...
Last Edited: Fri. May 28, 2021 - 02:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Do you have a known-good reference implementation of this protocol?

Is that what you mean by:

shahab_taheri wrote:
I have done this before by ATmega8, ATmega328, ATmega128..., 8MHz, 16MHz, 20MHz

 

So compare & contrast the working vs non-working cases ...

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: 1

It sounds like the OP wants to do softSPI, so is asking for code on specific mpu for that, rather then asking how to use the h/w SPI peripheral on the mpu, correct?

Perhaps this will help: https://forum.digikey.com/t/spi-...

using the h/w SPI on xmega app note: http://ww1.microchip.com/downloa...

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

ki0bk wrote:
It sounds like the OP wants to do softSPI

But he says it is not SPI - just something "like SPI"

 

So we really need a proper definition of what this "something like SPI, bit not SPI" protocol really is.

 

Impossible to give an implementation before we actually know what the protocol is!

 

Depending how "like" - or "unlike" - SPI it actually is, it might still be possible to use the hardware SPI peripheral ...

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: 1

Hi.

Dear ki0bk and Dear awnei   Thanks

I can't send picture. when sending the image, I get the following message: " You are not authorized to access this page."

 

I solved problem.

Unfortunately my problem was my inattention:

#define _clk    PORTC.IN & PIN0_bm
#define _data   PORTC.IN & PIN1_bm
#define _clk    (PORTC.IN & PIN0_bm)
#define _data   (PORTC.IN & PIN1_bm)

I forgot the parentheses!!!!!!!!!!

 

Thanks

Last Edited: Wed. Jun 2, 2021 - 03:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

shahab_taheri wrote:
when sending the image, I get the following message: " You are not authorized to access this page."

See: https://www.avrfreaks.net/forum/media-browser-you-are-not-authorized-access-page

Workarounds: https://www.avrfreaks.net/commen...

 

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

Thanks awneil