Posts: 7
Joined: Fri Oct 14, 2016 11:11 am

[Patch]bcm2835.c to move native-cs to gpio-cs

Wed Dec 21, 2016 11:29 pm

I need to change the native CS for another of the GPIO, in the following link have been able for the spi-bcm2835.c version, but I can not carry the changes to the arm version.

I have tried to change the line where the spi begin, and puts the GPIO in the correct mode but the program I use is not able to communicate.


Code: Select all

void bcm2835_spi_begin(void)
    volatile uint32_t* paddr;

    /* Set the SPI0 pins to the Alt 0 function to enable SPI0 access on them */
    bcm2835_gpio_fsel(RPI_GPIO_P1_26, BCM2835_GPIO_FSEL_ALT0); /* CE1 */
-   bcm2835_gpio_fsel(RPI_GPIO_P1_24, BCM2835_GPIO_FSEL_ALT0); /* CE0 */
+   bcm2835_gpio_fsel(RPI_GPIO_P1_22, BCM2835_GPIO_FSEL_OUTP); /* CE0 */
    bcm2835_gpio_fsel(RPI_GPIO_P1_21, BCM2835_GPIO_FSEL_ALT0); /* MISO */
    bcm2835_gpio_fsel(RPI_GPIO_P1_19, BCM2835_GPIO_FSEL_ALT0); /* MOSI */
    bcm2835_gpio_fsel(RPI_GPIO_P1_23, BCM2835_GPIO_FSEL_ALT0); /* CLK */
    /* Set the SPI CS register to the some sensible defaults */
    paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4;
    bcm2835_peri_write(paddr, 0); /* All 0s */
    /* Clear TX and RX fifos */
    bcm2835_peri_write_nb(paddr, BCM2835_SPI0_CS_CLEAR);
Then I made changes to the program I use to tell you that CS is in P1_22


Code: Select all

void MCP23S17PI::begin()
    if (!isBCM2835Initialized)
        if (!bcm2835_init())
            printf("Error initializing GPIO.");
            throw 1;


        bcm2835_spi_setClockDivider (BCM2835_SPI_CLOCK_DIVIDER_32);    // 3.9 MHz     
-       bcm2835_spi_chipSelect(_chipSelectPin);   
+ 	   bcm2835_spi_chipSelect(RPI_GPIO_P1_22);                     

        writeRegister(MCP23S17PI_IOCON, IOCON_INIT);

        isBCM2835Initialized = true;
But it does not work, I do not know what else to try.

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 6 guests