uc3b0256 as SPI master with multiple slaves

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

Hi,

I have a design using the uc3b0256 as SPI master, and 4 different slave chips connected to the SPI bus, using the 4 different chip select lines. I am using

PA25 as MISO
PA14 as MOSI
PA15 as SCK
PA16 as NPCS0
PA17 as NPCS1
PB05 as NPCS2
PB04 as NPCS3

I have an nrf905 on NPCS0, a SST25VF016B serial flash on NPCS1, a MCP23S17 on NPCS2, and a sub micro controller ATMEGA168PA as slave on NPCS3

Now I am battling to figure out how to setup the framework (using 3.4.0) to switch between the chips using either spi_selectChip/spi_unselectChip or spi_select_device/spi_deselect_device

I cant seem to find an example that talks to more than one slave chip. I only seem to be able to get the chip on NPCS0 to work, and the others dont seem to work. I checked the NPCS1/2/3 lines with scope and my code doesnt seem to be able to toggle them. I am uncertain what I need to do.

Can anyone perhaps provide an example to talk to more than one chip in SPI_MODE_0 with 8 bit data length. I have been using a clock speed of 8mhz for the slaves, and all 3 of the chips should work with this. My main clock on the uc3b0256 is 18.432mhz

Can anyone help ?

Thanks,

Steed.

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

The SPI has 2 chip select modes.
- Mode (MR.PSDEC=0) Selects the NPCS line connected to the first bit that is 0 (from lsb to msb) in MR.PCS. Posible selectable slaves are 4.
- Mode (MR.PSDEC=1) Sets the NPCS[0..3] equal to MR.PCS. This mode is normally used with a 4 to 16 line decoder. Making it possible to select 15 slaves.

The spi_selectChip use the mode selected by MR.PCDEC.
So when normal / MR.PSDEC=0 mode the following apply:
spi_selectChip(0) translates to NPCS0 = LOW;
spi_selectChip(1) translates to NPCS1 = LOW;
spi_sele... and so on.

In MR.PSDEC=1 mode this applies:
spi_selectChip(0) translates to NPCS[3..0] = 0b0000
spi_selectChip(1) translates to NPCS[3..0] = 0b0001
spi_selectChip(2) translates to NPCS[3..0] = 0b0010
.... and so on.

the spi_unselect() releases the NPCS lines to high again / or more pricisly sets MR.PCS=0xf.

In order to use the NPCS lines you of have to config the GPIO controller to connect the NPCS lines to the pins by the use of gpio_enable_module, perhaps that is the problem.

"It can NOT be solved in firmware later"