Recent

Author Topic: SPI implementation  (Read 227 times)

julkas

  • Sr. Member
  • ****
  • Posts: 382
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
SPI implementation
« on: September 21, 2019, 03:51:50 pm »
« Last Edit: September 21, 2019, 04:02:47 pm by julkas »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7430
Re: SPI implementation
« Reply #1 on: September 21, 2019, 04:10:16 pm »
Mostly it is only putting a byte in a register and then idling on a bit till it is sent and then reading the value of the register back?

Afaik Arduino has no SPI fifos or DMA, so it should be pretty simple.
« Last Edit: September 21, 2019, 04:14:59 pm by marcov »

ccrause

  • Full Member
  • ***
  • Posts: 177
Re: SPI implementation
« Reply #2 on: September 21, 2019, 05:47:50 pm »
Any SPI https://en.wikipedia.org/wiki/Serial_Peripheral_Interface impl. in Free Pascal (Arduino Uno R3)?
I found this - https://wiki.freepascal.org/AVR_Embedded_Tutorial_-_SPI/de.
As marcov said, it is not too complicated. The code in the tutorial seems good, so no reason not to start with that as your base. Copy the tutorial code into a unit and start testing - all code snippets up to:
Code: Pascal  [Select]
  1. end.
  You need to figure out which SPI port(s) and pins needs to be used for your chip (the tutorial configuration is for atmega328p) and configure the variables and constants in the interface section.  You also have to know the specific SPI configuration compatible with your slave device and configure the SPR register, although the values in the tutorial seems typical.

If you struggle, show your code and ask for more advice.

julkas

  • Sr. Member
  • ****
  • Posts: 382
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: SPI implementation
« Reply #3 on: September 21, 2019, 06:08:50 pm »
Thanks @markov, @ccrause.
To be continued...
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;