NetBurner 3.5.6
PDF Version
DSPI to Serial

DSPI to Serial Bridge

Overview

This NetBurner application demonstrates the Dual Serial Peripheral Interface (DSPI) functionality by creating a bridge between DSPI and UART serial communications. Data received on UART1 is transmitted via DSPI, and the received DSPI data is sent back through UART1, creating a complete bidirectional communication bridge.

Supported Platforms

  • MOD5441X - DSPI1 pins on J2 connector
  • NANO54415 - DSPI1 pins on carrier board

Hardware Requirements

  • NetBurner module with DSPI capability
  • UART1 connection for serial communication
  • SPI slave device or loopback jumper for testing
  • Serial terminal software for interaction

DSPI Pin Assignments

MOD5441X Platform

  • SCK (Clock): J2[25] (PINJ2_25_DSPI1_SCK)
  • SOUT (Master Out): J2[28] (PINJ2_28_DSPI1_SOUT)
  • SIN (Master In): J2[27] (PINJ2_27_DSPI1_SIN)
  • PCS0 (Chip Select): J2[30] (PINJ2_30_DSPI1_PCS0) - Optional/commented out

NANO54415 Platform

  • SCK (Clock): Pin 31 (PIN_31_DSPI1_SCK)
  • SOUT (Master Out): Pin 35 (PIN_35_DSPI1_SOUT)
  • SIN (Master In): Pin 33 (PIN_33_DSPI1_SIN)
  • PCS0 (Chip Select): Pin 15 (PIN_15_DSPI1_PCS0) - Optional/commented out

Application Functionality

Main Features

  1. UART to DSPI Bridge: Transfers UART data via SPI protocol
  2. DSPI to UART Echo: Returns received SPI data to UART
  3. Interrupt-Driven Transfers: Uses semaphores for efficient operation
  4. Loopback Testing: Simple jumper test without external devices
  5. Buffer Management: 10KB buffers for large data transfers

Program Flow

  1. Initialization
    • Initialize network stack and diagnostics
    • Configure DSPI1 pins for selected platform
    • Initialize DSPI with default parameters
    • Open UART1 at 115200 baud
    • Create semaphore for DSPI synchronization
  2. Main Loop
    • Monitor UART1 for incoming data
    • Transfer received data via DSPI
    • Wait for DSPI completion using semaphore
    • Send DSPI response back to UART1
    • Repeat continuously

Data Flow Architecture

UART1 --> Read Buffer --> DSPI TX --> SPI Bus --> External Device
^ |
| v
+---- Write Buffer <---- DSPI RX <---- SPI Bus <------+
@ Bus
Non-multiplexed bus mode (write only). Separate address and data buses. Reads are performed as AD-Mux...

Key Components

Files Structure

DSPI-to-Serial/
|-- src/
| +-- main.cpp # Complete application logic
|-- makefile # Build configuration
+-- README.md # This documentation

DSPI Configuration

Default Parameters:**

  • Module: DSPI1 (DEFAULT_DSPI_MODULE)
  • Baud Rate: 2 MHz (default)
  • Frame Size: 8 bits (default)
  • Chip Select: 0x0F (all CS inactive)
  • CS Polarity: 0x0F (active low)
  • Clock Polarity: 0x0 (idle low)
  • Clock Phase: 0x1 (capture on leading edge)
  • Data Output: Hi-Z when inactive

Core Functions

DSPI Operations:**

  • DSPIInit(): Initialize DSPI with default or specified parameters
  • DSPIStart(): Start interrupt-driven DSPI transfer
  • DSPIdone(): Poll for transfer completion (alternative to semaphore)

    Serial Operations:**

  • OpenSerial(): Configure UART1 with specified parameters
  • dataavail(): Check for incoming serial data
  • read(): Read data from UART buffer
  • writeall(): Write complete buffer to UART

    Synchronization:**

  • OS_SEM: Semaphore for interrupt-driven DSPI operation
  • Pend(): Wait for DSPI transfer completion
  • Post(): Signal transfer completion (done automatically by driver)

Testing and Usage

Loopback Testing (No External Device)

MOD5441X Setup:**

  • Place jumper between J2[27] (SIN) and J2[28] (SOUT)
  • This creates loopback for immediate echo testing

    NANO54415 Setup:**

  • Place jumper between Pin 33 (SIN) and Pin 35 (SOUT)
  • This creates loopback for immediate echo testing

    Expected Behavior:**

  1. Type characters in serial terminal
  2. Characters are sent via DSPI
  3. Looped-back data returns via DSPI
  4. Characters echo back to terminal

External SPI Device Testing

Connection Requirements:**

  • Connect DSPI pins to SPI slave device
  • Ensure common ground connection
  • Match voltage levels (typically 3.3V)
  • Add pull-up resistors if required by slave device

    Device Examples:**

  • SPI EEPROMs (25LC256, etc.)
  • SPI sensors (accelerometers, gyroscopes)
  • SPI displays (LCD controllers)
  • SPI ADC/DAC devices

Building and Deployment

Build Commands

# Build for specific platform
make PLATFORM=MOD5441X
make PLATFORM=NANO54415
# Load to device
make load DEVIP=<device_ip_address>

Serial Terminal Setup

  • Baud Rate: 115200
  • Data Bits: 8
  • Parity: None
  • Stop Bits: 1
  • Flow Control: None

Advanced DSPI Configuration

Custom Initialization Parameters

// Example: Custom DSPI setup
DSPIInit(1, // DSPI Module 1
4000000, // 4 MHz baud rate
16, // 16-bit frame size
0x0E, // CS0 active, others inactive
0x0F, // All CS active low
0x1, // Clock idle high
0x0, // Capture on trailing edge
FALSE, // Drive output when inactive
2, // CS to clock delay
3); // Delay after transfer
uint8_t DSPIInit(uint8_t SPIModule=DEFAULT_DSPI_MODULE, uint32_t Baudrate=2000000, uint8_t QueueBitSize=8, uint8_t CS=0x00, uint8_t CSPol=0x0F, uint8_t ClkPolarity=0, uint8_t ClkPhase=1, BOOL DoutHiz=TRUE, uint8_t QCD=0, uint8_t DTL=0)
Initialize a DSPI module.

Frame Size Options

  • 4-32 bits: Extended range beyond standard SPI
  • Automatic queuing: Hardware manages transfer queues
  • Interrupt driven: Efficient CPU utilization

Multiple Chip Select Management

// Different CS configurations
DSPIInit(1, 2000000, 8, 0x0E); // CS0 active
DSPIInit(1, 2000000, 8, 0x0D); // CS1 active
DSPIInit(1, 2000000, 8, 0x0B); // CS2 active

Performance Characteristics

Transfer Specifications

  • Maximum Baud Rate: Up to 25 MHz (platform dependent)
  • Frame Sizes: 4 to 32 bits (beyond standard 8/16-bit SPI)
  • Buffer Size: 10KB for both TX and RX operations
  • Latency: Interrupt-driven with minimal CPU overhead

Timing Characteristics

  • CS to Clock Delay: Configurable timing
  • Inter-frame Delay: Adjustable for slave device requirements
  • Clock Polarity/Phase: Full SPI mode support (0,0 to 1,1)

Troubleshooting

Common Issues

  1. No data transfer
    • Check pin configuration and connections
    • Verify DSPI initialization success
    • Confirm UART1 is opening correctly
    • Test with loopback jumper first
  2. Corrupted data
    • Check SPI clock polarity and phase settings
    • Verify baud rate is appropriate for slave device
    • Ensure proper voltage levels (3.3V logic)
    • Add decoupling capacitors near DSPI pins
  3. Semaphore timeout
    • Check if DSPI transfer is completing
    • Verify interrupt system is working
    • Monitor DSPI module status registers
    • Consider using polling mode as alternative
  4. Serial communication issues
    • Confirm UART1 baud rate (115200)
    • Check serial terminal settings
    • Verify UART1 pin connections
    • Test with different terminal software

Debug Techniques

Transfer Monitoring:**

// Add debug output
iprintf("DSPI transfer started, size: %d\n", num);
DSPI_SEM.Pend(0);
iprintf("DSPI transfer completed\n");

Buffer Inspection:**

// Display buffer contents
for(int i = 0; i < num; i++) {
iprintf("TX[%d]: 0x%02X, RX[%d]: 0x%02X\n",
i, TXBuffer[i], i, RXBuffer[i]);
}

Status Monitoring:**

// Check DSPI status (platform-specific registers)
iprintf("DSPI Status: 0x%08X\n", GetDSPIStatus(DEFAULT_DSPI_MODULE));
#define DEFAULT_DSPI_MODULE
Definition coldfire/cpu/MCF5441X/include/dspi.h:152

Application Extensions

Protocol Implementations

SPI EEPROM Interface:**

void WriteEEPROM(uint16_t address, uint8_t *data, int length) {
uint8_t cmd[3] = {0x02, address >> 8, address & 0xFF};
DSPIStart(DEFAULT_DSPI_MODULE, cmd, rxBuf, 3, &DSPI_SEM);
DSPI_SEM.Pend(0);
DSPIStart(DEFAULT_DSPI_MODULE, data, rxBuf, length, &DSPI_SEM);
DSPI_SEM.Pend(0);
}
uint8_t DSPIStart(uint8_t SPIModule, puint8_t transmitBufferPtr, volatile uint8_t *receiveBufferPtr, uint32_t byteCount, OS_SEM *finishedSem=NULL, uint8_t enableDMA=TRUE, int csReturnToInactive=DEASSERT_AFTER_LAST)
Start DSPI Data Transfer.

Sensor Data Acquisition:**

int16_t ReadADC(uint8_t channel) {
uint8_t cmd[3] = {0x01, (channel << 4), 0x00};
uint8_t response[3];
DSPIStart(DEFAULT_DSPI_MODULE, cmd, response, 3, &DSPI_SEM);
DSPI_SEM.Pend(0);
return ((response[1] << 8) | response[2]) & 0x0FFF;
}

Network Integration

TCP to DSPI Bridge:**

// Replace UART operations with TCP socket
int tcpFd = connect("192.168.1.100", 8080);
if(dataavail(tcpFd)) {
int num = read(tcpFd, (char*)TXBuffer, 10000);
DSPIStart(DEFAULT_DSPI_MODULE, TXBuffer, RXBuffer, num, &DSPI_SEM);
DSPI_SEM.Pend(0);
writeall(tcpFd, (char*)RXBuffer, num);
}
int dataavail(int fd)
Check the specified file descriptor to detmeine if data is available to be read.
int read(int fd, char *buf, int nbytes)
Read data from a file descriptor (fd).
int writeall(int fd, const char *buf, int nbytes=0)
Write the specified number of bytes to a file descriptor. Will block until all bytes are sent,...
int connect(const IPADDR &ipAddress, uint16_t remotePort, uint32_t timeout)
Establish a TCP connection to a remote host.
Definition tcp.h:1547

Web Interface Control:**

// Web-based SPI device control
void HandleSPICommand(uint8_t *cmd, int cmdLen, uint8_t *response) {
DSPIStart(DEFAULT_DSPI_MODULE, cmd, response, cmdLen, &DSPI_SEM);
DSPI_SEM.Pend(0);
}

Multi-Device Support

// Multiple SPI devices with different CS
void SelectDevice(int device) {
uint8_t csConfig = 0x0F & ~(1 << device); // Active low
DSPIInit(DEFAULT_DSPI_MODULE, 2000000, 8, csConfig);
}

Performance Optimization

High-Speed Transfers

// Optimize for maximum throughput
DSPIInit(DEFAULT_DSPI_MODULE, 25000000, 8, 0x0E, 0x0F, 0, 1, TRUE, 0, 0);

DMA Integration

// Use DMA for large transfers (if available)
void LargeDataTransfer(uint8_t *txData, uint8_t *rxData, int size) {
// Platform-specific DMA setup
StartDMATransfer(txData, rxData, size);
WaitForDMAComplete();
}

Interrupt Optimization

// Minimize interrupt latency
void __attribute__((interrupt)) DSPIInterruptHandler() {
// Keep handler minimal
ClearDSPIInterrupt();
SignalTransferComplete();
}

Related Examples

  • Serial Communication: UART bridging and protocols
  • CAN to Serial: Alternative communication bridging
  • I2C Examples: Inter-IC communication protocols
  • SPI Device Drivers: Specific SPI device implementations
  • Network Bridges: TCP/UDP to peripheral communication