Digole UART/I2C/SPI Display Library

Brilliant, thanks, I only wish I could contribute but I don’t have enough knowledge to do so and the time it would take me to learn would render my ability to help useless. If however there is data I can read to enlighten me, please point me at it and I will learn :slight_smile:

Chapter 24 of RM0008 the reference manual for the STM32F103, should get you started. You can download the PDF from ST Micro’s website

Ok, found the SPI data in chapter 25, this is heavy reading, I think I’m going to have to familiarize myself more with SPI before I can hope to get my head around this, what do you guys do, are you NASA scientists or something :slight_smile:

Thanks pra, I had reviewed that some time ago. I am trying to figure out how to use existing Spark and STM32 firmware code to do this so it minimizes potential conflict. :smile:

After having read a fair bit, it would occur to me that the CPHA bit needs changing to 0 for the SD card, and 1 for the digole so as to represent Mode 0 for the SD and Mode 1 for the digole. Am I on the right track or am I being a spanner?

rickpbush, that is correct. The SPI clock also needs to be adjusted.

Well, in my usual hacky way I’ve got it to work. What I’ve done is to set the mode and the speed in all methods. So, in all digole methods, the first thing it does is this

SPI.setClockDivider(SPI_CLOCK_DIV32);
SPI.setDataMode(1);

and in all SD methods, the first thing it does is this

SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV4);

I wonder if you would highlight the problems with this solution, are these calls going to hamper speed etc?

rickpbush, when you say “in all methods” do you really mean ALL methods? The only place it needs to be is in the SPI write method. Your approach is the right idea but I would like to find something faster if possible.

So, in DigoleSerialDisp.h, in the section starting with #if defined(_Digole_Serial_SPI_) you will find size_t write(uint8_t value). The new code should be:

size_t write(uint8_t value) {
    PIN_MAP[_SS].gpio_peripheral->BRR = PIN_MAP[_SS].gpio_pin; //Low
    delayMicroseconds(1);
    SPI.setDataMode(SPI_MODE1);
    SPI.setClockDivider(SPI_CLOCK_DIV32);
    SPI.transfer(value);
    delayMicroseconds(1);
    PIN_MAP[_SS].gpio_peripheral->BSRR = PIN_MAP[_SS].gpio_pin; //High
    return 1;
}

For the SD library, you will need to modify Sd2Card.cpp, at the end in function sparkSPISend() as follows:

inline __attribute__((always_inline))
uint8_t Sd2Card::sparkSPISend(uint8_t data) {
	uint8_t b=0;

        SPI.setDataMode(SPI_MODE0);
        SPI.setClockDivider(SPI_CLOCK_DIV4);
	if (SPImode_) {				// SPI Mode is Hardware so use Spark SPI function
		b = SPI.transfer(data);
	}
	else {						// SPI Mode is Software so use bit bang method
         ...

Give that a shot and let me know how it goes.:slight_smile:

Hi Peekay, for me, putting

SPI.setDataMode(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV32);

into digole write stopped digole from displaying anything at all, there are some lines commented out in there, such as

//SPI.setDataMode(3);

and

//SPI.setDataMode(0);

which makes me wonder if Timb had the same ide lol.

I’ll continue to experiment with your solution and let you know how I get on.

Ah, simple, just had to place

SPI.setDataMode(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV32);

before PIN_MAP, which I assume sets the ss low.

Oops, my bad! Good catch.

Also, I’ve put

SPI.setDataMode(SPI_MODE0);
 SPI.setClockDivider(SPI_CLOCK_DIV4);

inside the if statement that tests for hardware SPI on the SD because otherwise it would set it for soft SPI also. Unfortunately this kills it and the card wont initialize, I tried settin ss high first too but have yet to have any success.

I will look after the hockey game

lol, odly, I’ve removed

SPI.setDataMode(SPI_MODE0);
    SPI.setClockDivider(SPI_CLOCK_DIV4);

and put them into the higher level functions in File, like File::read() & available and it works now, but not if those lines are in Sd2Card::sparkSPISend. Odd, anyway, although we are reinitializing the spi each time it’s working and I have my pins back :slight_smile:

rickpbush, I’m glad it’s working for you. I believe the problem has to do with timing of the SPI changes and I will work to find a more transparent solution. :smile:

@rickpbush I'm trying to get the same setup going as you have.

What were the functions you added these to?

@peekay123 Have you made any updates to the library recently? (Have you committed them to GitHub?) We need to clean up a few things and submit it for inclusion in the IDE!

2 Likes

@timb, nothing new so feel free to push it out. :slight_smile:

1 Like

@Hootie81, I reset the SPI each time I used the SD card, later today I’ll upload my code and put a link on here for you.

I put the sd.begin(… before each time i access the sd card and its working again now, not the most efficient but like you say it works, thanks. it will be interesting when i try and put another spi rfid reader on the bus too :smile: