Hi,
I just started with the AM335x with the ICE board. I wrote the attached program
/* * main.c * * uses code from mcspiFlash from starterware examples */ #include "soc_AM335x.h" #include "hw_control_AM335x.h" #include "evmAM335x.h" #include "interrupt.h" #include "uartStdio.h" #include "hw_types.h" #include "mcspi.h" #include "gpio_v2.h" #define MCSPI_OUT_FREQ (3000000u) #define MCSPI_IN_CLK (48000000u) #define GPIO_INSTANCE_ADDRESS (SOC_GPIO_1_REGS) #define GPIO_INSTANCE_PIN_NUMBER (8) static void ModulesConfigure(void); static void IntConfigure(void); static void GPIOIsr(void); extern unsigned int McSPIChannelStatusGet(unsigned int baseAdd, unsigned int chNum); unsigned int chNum = 1; unsigned int outint = 0x00aaaaaa; unsigned int inint = 0; long long unsigned int sampleaccu = 0; unsigned int decimation = 1000; volatile unsigned int samplecount = 0; long long unsigned int meanvalue = 0; unsigned int i = 0; unsigned int range = 5000; void main(void) { ModulesConfigure(); // Map Interrupts to AINTC IntConfigure(); UARTPuts("\nSPI ADC gateway\n", -1); while (1){ while (samplecount<decimation); meanvalue = sampleaccu; sampleaccu = 0; samplecount = 0; meanvalue *= range; meanvalue /= decimation; meanvalue = (meanvalue>>23); UARTPuts("\nMean value: ", -1); UARTPutNum(meanvalue); UARTPuts("mV\n", -1); } } static void ModulesConfigure(void){ UARTStdioInit(); // Enable the clocks for McSPI0 module. McSPI0ModuleClkConfig(); // Perform Pin-Muxing for SPI0 Instance McSPIPinMuxSetup(0); // Reset the McSPI instance. McSPIReset(SOC_SPI_0_REGS); // Enable master mode of operation. McSPIMasterModeEnable(SOC_SPI_0_REGS); // Perform the necessary configuration for master mode. McSPIMasterModeConfig(SOC_SPI_0_REGS, MCSPI_SINGLE_CH, MCSPI_TX_RX_MODE, MCSPI_DATA_LINE_COMM_MODE_1, chNum); // Configure the McSPI bus clock depending on clock mode. McSPIClkConfig(SOC_SPI_0_REGS, MCSPI_IN_CLK, MCSPI_OUT_FREQ, chNum, MCSPI_CLK_MODE_0); // Configure the word length. McSPIWordLengthSet(SOC_SPI_0_REGS, MCSPI_WORD_LENGTH(24), chNum); // Configure chip select McSPICSEnable(SOC_SPI_0_REGS); McSPI0CSPinMuxSetup(chNum); McSPICSPolarityConfig(SOC_SPI_0_REGS, MCSPI_CS_POL_LOW, chNum); McSPICSAssert(SOC_SPI_0_REGS, chNum); // Enabling functional clocks for GPIO1 instance. GPIO1ModuleClkConfig(); // Selecting GPIO1[8] pin for use. HWREG(SOC_CONTROL_REGS + CONTROL_CONF_UART_CTSN(0)) = (CONTROL_CONF_UART0_CTSN_CONF_UART0_CTSN_RXACTIVE | CONTROL_CONF_UART0_CTSN_CONF_UART0_CTSN_PUTYPESEL | CONTROL_CONF_MUXMODE(7)); // Enabling the GPIO module. GPIOModuleEnable(GPIO_INSTANCE_ADDRESS); // Perform a module reset of the GPIO module. GPIOModuleReset(GPIO_INSTANCE_ADDRESS); // Set the specified pin as an output pin. GPIODirModeSet(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_DIR_INPUT); GPIOPinIntEnable(GPIO_INSTANCE_ADDRESS, GPIO_INT_LINE_1, GPIO_INSTANCE_PIN_NUMBER); GPIOIntTypeSet(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_INT_TYPE_FALL_EDGE); } /* Interrupt mapping to AINTC and registering ISR */ static void IntConfigure(void) { // Enable IRQ in CPSR. IntMasterIRQEnable(); // Initialize ARM interrupt controller IntAINTCInit(); // Register GPIOIsr interrupt handler IntRegister(SYS_INT_GPIOINT1A, GPIOIsr); // Set Interrupt Priority IntPrioritySet(SYS_INT_GPIOINT1A, 0, AINTC_HOSTINT_ROUTE_IRQ); // Enable system interrupt in AINTC IntSystemEnable(SYS_INT_GPIOINT1A); } static void GPIOIsr(void){ // Enable SPI channel McSPIChannelEnable(SOC_SPI_0_REGS, chNum); McSPITransmitData(SOC_SPI_0_REGS,(unsigned int)(outint), chNum); // Wait for end of transfer while (!(McSPIChannelStatusGet(SOC_SPI_0_REGS, chNum) & MCSPI_CH_STAT_EOT)); // Read received data inint = (McSPIReceiveData(SOC_SPI_0_REGS, chNum) & 0x00ffffff); sampleaccu += (long long unsigned int)inint; samplecount++; // Disable SPI channel McSPIChannelDisable(SOC_SPI_0_REGS, chNum); GPIOPinIntClear(GPIO_INSTANCE_ADDRESS, GPIO_INT_LINE_1, GPIO_INSTANCE_PIN_NUMBER); }
How do I best adapt my program to the SYS/BIOS paradigms of the tiescappl? Can I access the registers in SYS/BIOS in the way I do in my program? Or is it easier to integrate EtherCAT into my existing program?
Thank you,
Manuel