SPI master bit turns off unexpectedly

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

I'm trying to establish an SPI communication with a display. Here's my code which enables it:

    SPI->CTRL=SPI_MASTER_bm|SPI_MODE0_bm|SPI_PRESCALER_DIV4_gc;
    SPI->CTRL|=SPI_ENABLE_bm;

SPI is a member of my class which is successfully initialized to point to SPIC.

The code is finished, but there's nothing on the screen. I used the Embedded Debugger to see what the SPI points to and it's the same as SPIC. I saw in the memory watch and in the I/O watch. The Enable bit is set, but the master bit isn't. I don't know what could possibly turn off that bit. I Ctrl+F'd over the code to see if maybe there's an assignment writing into the control register. At first, I found out, but after fixing the code, I see the SPIC_MASTER bit set. After stepping through the code, the bit gets cleared. Is this an error in the microcontroller?

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

Are you shure about correct SS pin control?

 

"When configured as a Master, the SPI interface has no automatic control of the SS line. The SS pin must be configured as output, and controlled by user software.

If the SS pin is configured as an input, it must be held high to ensure Master operation. If the SS pin is input and being driven low by external circuitry,

he SPI module will interpret this as another master trying to take control of the bus."

and clears SPI_MASTER bit

 

wbr, ReAl

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

I left the SS pin floating (disconnected). I'll try to see if it works now. Now I gotta unpack and rewire everything.

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

I fixed the SPI, but the display still isn't working.

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

I left the SS pin floating (disconnected)

From the master or the slave??

Regardless of what you do it MUST BE an output in the master as sansan points out above.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Regardless of what you do it MUST BE an output in the master as sansan points out above.

OR if left as an input, is must be held high (either externally, or via the internal pullup).  If it goes low as an input, the SPI peripheral switches over to slave mode.  This is by design for use in multi-master environments.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]