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. -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.