SPI plane code

I am looking for the plane C or partly ASM for sending
SPI as master only. In first instance it is now for the
Atmel 328 and in a later version it is for the STM32C8T6.
The goal is to send multiple bytes without "gaps" at half
clockspeed.

Working programming example is below.

void SendFTWdata() {

digitalWrite (CS, LOW);

shiftOut16(DATA, CLOCK, Instruction_header_FTW); // 16 bits
shiftOut8(DATA, CLOCK, Register_data_FTW[5]); // 8 bits
shiftOut8(DATA, CLOCK, Register_data_FTW[4]); // 8 bits
shiftOut8(DATA, CLOCK, Register_data_FTW[3]); // 8 bits
shiftOut8(DATA, CLOCK, Register_data_FTW[2]); // 8 bits
shiftOut8(DATA, CLOCK, Register_data_FTW[1]); // 8 bits
shiftOut8(DATA, CLOCK, Register_data_FTW[0]); // 8 bits

digitalWrite (CS, HIGH);

digitalWrite (IO_update, HIGH);
digitalWrite (IO_update, LOW);

}

/////////////////////////////////////////////////////////////////

void shiftOut8(uint8_t dataPin, uint8_t clockPin, uint8_t val) {

for (i = 0; i < 8; i++) {

digitalWrite(dataPin, !!(val & (1 << (7 - i))));

digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}

void shiftOut16(uint8_t dataPin, uint8_t clockPin, uint16_t val) {

for (i = 0; i < 16; i++) {

digitalWrite(dataPin, !!(val & (1 << (15 - i))));

digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}

spi_question.txt (1.2 KB)

it's "open source" Doh

Mark

holmes4:
it's "open source" Doh

Mark

I know, but why inventing the wheel again. I need only the
source where to find the right one :wink:

pe1mxp:
I am looking for the plane C or partly ASM for sending
SPI as master only. In first instance it is now for the
Atmel 328 and in a later version it is for the STM32C8T6.

The Atmel Amega 328 datasheet has sample code for the Atmega 328. I'm guessing that the STMxxx datasheet will have something similar.

The source code for the Arduino SPI library is in the Arduino IDE.

...R

The source code for the Arduino SPI library is in the Arduino IDE.

And that's why we call it "open source" Doh

Mark

holmes4:
And that's why we call it "open source" Doh

I'm well aware that you know that.

I was concerned that the OP might not.

...R

Well, something described like this Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral Interface - for Arduino

@robin2 sorry the comment was aimed at the op and I think that he still doesn't get it!

Mark

Well, have it running 8bytes at 8Mhz, only removing the "gaps" between the bytes.
I saw this trick this week on a website but forgot which website.
With 0,135us between CS and I/O update way too long time.

pe1mxp:
Well, have it running 8bytes at 8Mhz, only removing the "gaps" between the bytes.
I saw this trick this week on a website but forgot which website.
With 0,135us between CS and I/O update way too long time.

If you want help please write a message that we can understand. This (and your Reply #6) seem like they are brief summaries of part of something that was in your mind.

...R