Using a NANO54415. I have multiple devices on the SPI port. The only place I've found to set the chip-selects is through the DSPIInit() function. Do I need to call DSPIInit() before every transfer when all I need to change is the chip-select, or can I just set Command_Mask accordingly before each transfer?
Update:
I'm using SPI1, and I'm running example program DSPI2Serial. I've tried running the example with each of the 3-chip-selects active. Chip-selects SPI_CS0 and SPI_CS1 work as expected, in that they are logic high when inactive and logic low when transferring. But SPI_CS2 does not work at all. It is always logic low, and never changes state.
I added the pin definitions for the chip-selects to the example, and then changed DSPIInit() for each chip-select, with CS = 0x0E for CS0, CS = 0x0D for CS1, and CS = 0x0B for CS2. Did I miss something?
Update 2:
I changed the 3 SPI chip selects to GPIO, and manually set and cleared each CS signal. Pins 15 and 37 work as expected. Pin 39 is stuck low. Is this pin even connected to anything on the NANO module, or is it mismarked, or what?
Pins[15].function(PIN_15_GPIO); // SPI Chip-Select 0
Pins[37].function(PIN_37_GPIO); // SPI Chip-Select 1
Pins[39].function(PIN_39_GPIO); // SPI Chip-Select 2
Pins[15] = 1;
Pins[37] = 1;
Pins[39] = 1;
DSPIInit(); // Keep overloaded defaults
while(1)
{
Pins[39] = 0;
DSPIStart(DEFAULT_DSPI_MODULE, TXBuffer,
RXBuffer, num, &DSPI_SEM); // Send data via DSPI
OSSemPend( &DSPI_SEM, 0 ); // Wait for DSPI to complete
//writeall(U1FD, (char*)RXBuffer, num); // Send DSPI RX via UART1
Pins[39] = 1;
OSTimeDly( 2 * TICKS_PER_SECOND );
}
Steve
SPI Chip-Selects
Re: SPI Chip-Selects
What is your nano plugged into? If its the netburner nano dev board, spi cs2 is used for the external flash card slot, so you have other circuitry involved on the dev board.
-
- Posts: 630
- Joined: Mon May 12, 2008 10:55 am
Re: SPI Chip-Selects
DOH! That was it. I assumed the CS2 chip-select was an input to the SD card, so it didn't matter.
Any thoughts on whether I need to call DSPIInit() every time I want to change the spi chip-selects?
Thanks.
Any thoughts on whether I need to call DSPIInit() every time I want to change the spi chip-selects?
Thanks.
Re: SPI Chip-Selects
If its the same spi port, than just change the bits in the command register. Pretty easy to set that up to test it, just put a scope on the two chip selects.
Re: SPI Chip-Selects
Steve,
In the current system, yes you'll need to call DSPIInit every time to change it.
However... I'm finally getting around to the object based interface that I've wanted since the beginning (back before I really knew how to read a hardware manual, hence the straight port from our older QSPI driver). I'm reworking the driver to be based on an underlying object instead of a single function and driver context. This will let you have multiple chip selects and baudrates.
-Dan
In the current system, yes you'll need to call DSPIInit every time to change it.
However... I'm finally getting around to the object based interface that I've wanted since the beginning (back before I really knew how to read a hardware manual, hence the straight port from our older QSPI driver). I'm reworking the driver to be based on an underlying object instead of a single function and driver context. This will let you have multiple chip selects and baudrates.
Code: Select all
class DSPIModule
{
uint32_t m_moduleNum;
uint32_t m_ctar0;
uint32_t m_ctar1;
bool m_enableDMA;
OS_SEM *m_finishedSem;
public:
bool m_inProgress;
static DSPIModule *lastCxts[DSPI_MODULE_COUNT];
static dspiDriverStruct driverCxt[DSPI_MODULE_COUNT];
DSPIModule();
DSPIModule( BYTE SPIModule, DWORD baudRateInBps = 2000000,
BYTE transferSizeInBits = 8, BYTE peripheralChipSelects = 0x00,
BYTE chipSelectPolarity = 0x0F, BYTE clockPolarity = 0,
BYTE clockPhase = 1, BOOL doutHiz = TRUE,
BYTE csToClockDelay = 0, BYTE delayAfterTransfer = 0 );
BYTE Init( DWORD baudRateInBps = 2000000,
BYTE transferSizeInBits = 8, BYTE peripheralChipSelects = 0x00,
BYTE chipSelectPolarity = 0x0F, BYTE clockPolarity = 0,
BYTE clockPhase = 1, BOOL doutHiz = TRUE,
BYTE csToClockDelay = 0, BYTE delayAfterTransfer = 0 );
BYTE Start( uint8_t *transmitBufferPtr, volatile uint8_t *receiveBufferPtr,
uint32_t byteCount, int csReturnToInactive = DEASSERT_AFTER_LAST );
bool EnableDMA(bool enableDMA = true);
inline bool DisableDMA() { return EnableDMA(false); }
bool SetSem( OS_SEM *finishedSem );
inline bool ClrSem() { return SetSem(NULL); }
inline bool Done() { return m_inProgress; }
static BOOL Done( BYTE SPIModule );
};
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc
Re: SPI Chip-Selects
I have some code working on the MOD54415 that accesses the DSPI FIFO as if it was a queue (like on the earlier QSPI modules). Dan gave me a bit of encouragement and help initially and it's now working ok. I could send or post it if you want, but it's really just using the sim data type to access the registers in the processor very much like on the QSPI of say the MOD5272.
As Dan suggests, it helps to become familiar (very familiar) with chap 40 of the Freescale Reference Manual (Chapter 40 for the MOD54415). You'll probably find it in C:\nburn\docs\FreescaleManuals.
This has reminded me that I think there's an obvious bug in the slew rate settings in dspi.cpp. I'd prepared some notes but never posted them. I'll raise another topic as it's not really for here.
As Dan suggests, it helps to become familiar (very familiar) with chap 40 of the Freescale Reference Manual (Chapter 40 for the MOD54415). You'll probably find it in C:\nburn\docs\FreescaleManuals.
This has reminded me that I think there's an obvious bug in the slew rate settings in dspi.cpp. I'd prepared some notes but never posted them. I'll raise another topic as it's not really for here.
Gavin Murray