StarterWare SPI on BeagleBone Black / Debian

Hi,

I want to use SPI through direct memory access on Debian, here is what I got so far:

`
int enableSPIClock()
{
// map a pointer to the clock control block
pClockControl = (char*)mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, memFd, SOC_CM_PER_REGS);

HWREG(pClockControl + CM_PER_SPI1_CLKCTRL) |= CM_PER_SPI1_CLKCTRL_MODULEMODE_ENABLE;
while(CM_PER_SPI1_CLKCTRL_MODULEMODE_ENABLE != (HWREG(pClockControl + CM_PER_SPI1_CLKCTRL) & CM_PER_SPI1_CLKCTRL_MODULEMODE));

return 0;
}

int enableSPI()
{
enableSPIClock();

McSPIReset(spi);
McSPICSEnable(spi);
McSPIMasterModeEnable(spi);

// set D0 as output-MOSI , set D1 as input-MISO
McSPIMasterModeConfig(spi, MCSPI_MULTI_CH, MCSPI_TX_RX_MODE, MCSPI_CH0CONF_DPE0_ENABLED | MCSPI_CH0CONF_DPE1_DISABLED, chNum);
McSPIClkConfig(spi, 48000000, 6000000, chNum, MCSPI_CLK_MODE_0);
McSPIWordLengthSet(spi, MCSPI_WORD_LENGTH(8), chNum);
McSPICSPolarityConfig(spi, MCSPI_CS_POL_LOW, chNum);
McSPITxFIFOConfig(spi, MCSPI_TX_FIFO_ENABLE, chNum);
McSPIRxFIFOConfig(spi, MCSPI_RX_FIFO_ENABLE, chNum);

return 0;
}

int spiWrite(uint8_t *tx, uint32_t length)
{
// cs line is forced to low state.
McSPICSAssert(spi, chNum);

// enable the spi channel for communication.
McSPIChannelEnable(spi, chNum);

while (length > 0)
{
McSPITransmitData(spi, (unsigned int)(*tx++), chNum);
length–;

unsigned int rx = McSPIReceiveData(spi, chNum);
}

// force cs line to the inactive state.
McSPICSDeAssert(spi, chNum);

// Disable the spi channel.
McSPIChannelDisable(spi, chNum);
}

`

I’m writing to a DAC and every 2nd or 3rd message actually goes through (gets recognized by the DAC).

The StarterWare site http://processors.wiki.ti.com/index.php/StarterWare_McSPI references the Interrupt and DMA mode, but I’m not sure if I should use them…?
If anyone has tried a similar thing I’d be more than happy to hear about it.

Hello Gregor,

I’m actually working on a project incolving a SPI connection between a BeagleBone black and an AD7606 (ADC). I have a couple of problems to enable properly the SPI connection, could you give me more details about how you have done it ? (if it worked).

I’m programming the BB_black in bare-metal, and it will communicate with the ADC using the SPI, so I really need to find out how to do it in order for my system to work.

Best regards,

Cedric.

Bare Metal is not Debian? If you use bare metal you need to set up all pin mux and initialize memory controller typically with a gel file in CCS. Briefly looking at your code assuming nothing is interference with mux I’d make sure your SPI chipselect is properly timed with a scope if you’re truly getting commands through. Also a cheap Salae logic analyzer is very handy for what you’re doing costs about $200