Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gpio CS? #2

Open
kanflo opened this issue Jul 29, 2015 · 7 comments
Open

Support gpio CS? #2

kanflo opened this issue Jul 29, 2015 · 7 comments

Comments

@kanflo
Copy link

kanflo commented Jul 29, 2015

Your driver seems like a nice fit for my project but I will have more than one SPI device leading to the need for GPIO chip selects. Of course the pin toggling could be made outside of the SPI driver but imho it would be nicer to have it inside the driver as it belongs to "the SPI domain". What do you think?

@MetalPhreak
Copy link
Owner

It's an idea I've thought about a while back when writing this, but haven't gotten around to implementing it. If I get some time over the next couple of weeks I'll take a look at doing it. I'm sure I'll need to do it at some point in the future for one of my projects anyway! :)

@elmorejd
Copy link

I second this! Is there a register for setting which GPIO is used for CS?

@kanflo
Copy link
Author

kanflo commented Nov 24, 2015

I removed the line PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2); from spi_init_gpio(...) and added toggling of my chosen GPIO CS manually:

gpio_write(cs_pin, 0);
spi_tx16(iHSPI, data[0] << 8 | data[1]);
gpio_write(cs_pin, 1);

The hardware SPI block can only use GPIO15 as CS. Note that in SPI the CS signal is active when low.

@elmorejd
Copy link

Great that works pretty well. Thanks.

@KaDw
Copy link

KaDw commented Oct 8, 2017

@kanflo @elmorejd You had any problems with software CS? I'm trying to use GPIO4 as CS.

void max7219_write(uint8 reg, uint8 value){
    uint16_t data = (reg << 8) | value;
    GPIO_OUTPUT_SET(4, 0); // cs low
    spi_tx16(HSPI, data);
    GPIO_OUTPUT_SET(4, 1); // cs high
}

This is what I get with the code above: (only CS and CLK lines)

spi

I'm a bit lucky because first 4 bits of data for MAX7219 doesn't matter so this is working. Also last transaction is skipped. If I switch CS to hardware mode everything works like a charm. Unfortunately I have boards manufactered and CS is wired to GPIO4
Any ideas what could go wrong? I know it's a bit old issue :P

@MetalPhreak
Copy link
Owner

MetalPhreak commented Oct 8, 2017 via email

@KaDw
Copy link

KaDw commented Oct 8, 2017

Thanks for very fast reply! I'm checking if spi is busy like you said and now everything is OK

Working code:

void max7219_write(uint8 reg, uint8 value){
    uint16_t data = (reg << 8) | value;
    GPIO_OUTPUT_SET(4, 0); // cs low
    spi_tx16(HSPI, data);
    while(spi_busy(HSPI)); // ADDED
    GPIO_OUTPUT_SET(4, 1); // cs high
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants