Skip to content

Instantly share code, notes, and snippets.

@rafacouto
Created March 15, 2017 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafacouto/2b6b7da10813ddb6483898d2135e7f58 to your computer and use it in GitHub Desktop.
Save rafacouto/2b6b7da10813ddb6483898d2135e7f58 to your computer and use it in GitHub Desktop.
-- clock_div: SPI clock divider, f(SPI) = 80 MHz / clock_div
function spi_test(clock_div)
spi.setup(1, spi.MASTER, spi.CPOL_HIGH, spi.CPHA_HIGH, 8, clock_div, spi.FULLDUPLEX)
for n=0,256 do
r = { spi.send(1, n) }
--print(n, r[2])
if n > 0 and ((n-1)*2) % 256 ~= r[2] then print("ERROR!") ; return end
end
print("Test OK! :)")
end
-- test with ATtiny 2313:
-- > spi_test(19)
-- ERROR!
-- > spi_test(20)
-- Test OK! :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment