Mega644P USART as MSPIM clock issue

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

I'm trying to use one of the USARTs in the Meag644P as an SPI master to read data from a MAX31855 Thermocouple-to-digital converter. It has Only ChipSelect, Clock, and Data Out connections.

Below are my register settings

// PB0 = XCK0 - Output
// PD1 = TXD0 - Output
// PD0 = RXD0 - Input

UBRR0 = 0; // Allows 1Mbps at 16MHz clock.
DDRB |= (1<<DDB0); //XCK0 as output
UCSR0C = ((1

The problem is, the clock never stops. It just keeps running. There was another post here about a 2313A with a clock that was always running, but he wasn't setting both UMSELnX bits.

Reading data via:

for (uint8_t n=0; n<4; n++)
    {
	while( !( UCSR0A & (1<<UDRE0)) );
        UDR0 = 0;// send a null byte
        while( !(UCSR0A & (1<<TXC0)) );// wait until transfer ends
        thermodata = (thermodata<<8) + UDR0;
    }

Normal SPI works great and I can read data with no issues.

Am I missing something here? Is the disconnected TXD0 line causing some sort of issue? Why does the clock just keep running?

Thanks.

Jim M., Rank amateur AVR guy.

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

Full disclosure: While I've done a lot of AVR apps, I haven't used the USART-as-SPI feature.

I recalled several threads mentioning this feature. Most point back to the datasheet code that you have adapted for your needs.

Nothing jumps out at me about your code. The only thing I can think of is that the "driver" code is executing repeatedly. As the UDR is double-buffered it may well appear as a continuous clock stream?

If it were me, I'd make a single-byte send/receive primitive with some canned data and invoke it >>once<<; say, when a button is pressed. Then observe the output waveforms on a 'scope. How many clocks do you get?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I've seen the "double buffered" comment made before.
I'll try out your suggestions. The problem I'm having it that I'm running out of pins. I was hoping to use 1 USART for actual USART traffic from an FTDI chip, one USART in MSPIM mode for the Thermocouple converters. Leaving the SPI port free for programming. Sometimes the thermoucouple chips cause ICSP errors during programming so I have to unplug the clock wire. But I'm just about out of pins. I may HAVE to use the SPI pins for double duty and have a "programming jumper" on the board. But I digress.

Thanks for your help.

Jim M., Rank amateur AVR guy.

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

Quote:

Leaving the SPI port free for programming. Sometimes the thermoucouple chips cause ICSP errors during programming so I have to unplug the clock wire.

Are the thermocouple chips true SPI, with a chip-select? Then use a weak pullup/pulldown to keep them de-selected when the AVR is in reset. Done all the time...

But anyway, AFAIK the USART-as-SPI should work. Post the solution when you find it.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:

Are the thermocouple chips true SPI, with a chip-select? Then use a weak pullup/pulldown to keep them de-selected when the AVR is in reset. Done all the time...

Well now you're just making too much sense. Nice simple solution! 10-15K pullup oughta do it.

Jim M., Rank amateur AVR guy.

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

Quote:

10-15K pullup oughta do it.

We usually use like 100k--less "fighting" the aux pulling resistor during normal operation.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

OK then. I'll recalibrate my feelings around "weak".
If you've had 100K work for you, I'll give 'er a go.
Thanks again.

Jim M., Rank amateur AVR guy.

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

theusch wrote:
Quote:

10-15K pullup oughta do it.

We usually use like 100k--less "fighting" the aux pulling resistor during normal operation.

Dang! With the MAX31855s connected and a 100k pullup on the chip select lines, I can program the 644 at 2MHz with no issues whatsoever. Awesome.

Jim M., Rank amateur AVR guy.