@haricot Im working on the code of ControlBlockService2 , This is a full working soft to mcp23s17 but the driver to control the chip is bcm2835.c and not is included the lines to use aany GPIO pin to CS, RPi last versions can drive CS from any GPIO pin makin an overlay and i compile one but the ControlBlock (CB) not works in a different pins that 7 or 8:
The especific line on the code is here:
| bcm2835.h |
| |
| |
| |
| |
| typedef enum |
| { |
| BCM2835_SPI_CS0 = 0, |
| BCM2835_SPI_CS1 = 1, |
| BCM2835_SPI_CS2 = 2, |
| BCM2835_SPI_CS_NONE = 3, |
| |
| } bcm2835SPIChipSelect; |
Here
airspayce(.com)/mikem/bcm2835/group__constants.html#ga29bba154633d37d07fa130a86e4a1f2aurl REMOVE THE PARENTESIS I SPAM PROBLEM WITH TE FORUM
explain the options por CS but i find another version of the driver.
This include the GPIO CS options for a arduino project, i added the code and compile:
| |
| |
| |
| typedef enum |
| { |
| BCM2835_SPI_CS0 = 0, |
| BCM2835_SPI_CS1 = 1, |
| BCM2835_SPI_CS2 = 2, |
| BCM2835_SPI_CS_NONE = 3, |
| |
| |
| |
| BCM2835_SPI_CS_GPIO4 = RPI_V2_GPIO_P1_07, |
| BCM2835_SPI_CS_GPIO17 = RPI_V2_GPIO_P1_11, |
| BCM2835_SPI_CS_GPIO18 = RPI_V2_GPIO_P1_12, |
| BCM2835_SPI_CS_GPIO22 = RPI_V2_GPIO_P1_15, |
| BCM2835_SPI_CS_GPIO23 = RPI_V2_GPIO_P1_16, |
| BCM2835_SPI_CS_GPIO24 = RPI_V2_GPIO_P1_18, |
| BCM2835_SPI_CS_GPIO25 = RPI_V2_GPIO_P1_18, |
| BCM2835_SPI_CS_GPIO28 = RPI_V2_GPIO_P5_03, |
| BCM2835_SPI_CS_GPIO29 = RPI_V2_GPIO_P5_04, |
| BCM2835_SPI_CS_GPIO30 = RPI_V2_GPIO_P5_05, |
| BCM2835_SPI_CS_GPIO31 = RPI_V2_GPIO_P5_06 |
| |
| } bcm2835SPIChipSelect; |
After change the inicialization of the driver in bcm2835.c:
| void bcm2835_spi_begin(void) |
| { |
| volatile uint32_t* paddr; |
| |
| |
| bcm2835_gpio_fsel(RPI_GPIO_P1_26, BCM2835_GPIO_FSEL_ALT0); |
| - bcm2835_gpio_fsel(RPI_GPIO_P1_24, BCM2835_GPIO_FSEL_ALT0); |
| + bcm2835_gpio_fsel(RPI_GPIO_P1_22, BCM2835_GPIO_FSEL_OUTP); |
| bcm2835_gpio_fsel(RPI_GPIO_P1_21, BCM2835_GPIO_FSEL_ALT0); |
| bcm2835_gpio_fsel(RPI_GPIO_P1_19, BCM2835_GPIO_FSEL_ALT0); |
| bcm2835_gpio_fsel(RPI_GPIO_P1_23, BCM2835_GPIO_FSEL_ALT0); |
| |
| |
| paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4; |
| bcm2835_peri_write(paddr, 0); |
| |
| |
| bcm2835_peri_write_nb(paddr, BCM2835_SPI0_CS_CLEAR); |
| } |
| |
| void bcm2835_spi_end(void) |
| { |
| |
| bcm2835_gpio_fsel(RPI_GPIO_P1_26, BCM2835_GPIO_FSEL_INPT); |
| - bcm2835_gpio_fsel(RPI_GPIO_P1_24, BCM2835_GPIO_FSEL_INPT); |
| + bcm2835_gpio_fsel(RPI_GPIO_P1_22, BCM2835_GPIO_FSEL_INPT); |
| bcm2835_gpio_fsel(RPI_GPIO_P1_21, BCM2835_GPIO_FSEL_INPT); |
| bcm2835_gpio_fsel(RPI_GPIO_P1_19, BCM2835_GPIO_FSEL_INPT); |
| bcm2835_gpio_fsel(RPI_GPIO_P1_23, BCM2835_GPIO_FSEL_INPT); |
| } |
And finally i change the file mcp23s17pi.cpp and recompile CB:
bcm2835_spi_begin();
bcm2835_spi_setClockDivider (BCM2835_SPI_CLOCK_DIVIDER_32);
bcm2835_spi_chipSelect(BCM2835_SPI_CS_GPIO25);
All is compiled without errors but not work :_(