X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=betty%2Fspi.c;fp=betty%2Fspi.c;h=198213d0a2979d35628897ae3fa74595fef19bbf;hb=b4ca71fc214ba3c58cec25661ba1f81cf7b1b871;hp=0000000000000000000000000000000000000000;hpb=d6814c7408b23db8a441f731b44d4b638df24c64;p=my-code%2Farm.git diff --git a/betty/spi.c b/betty/spi.c new file mode 100644 index 0000000..198213d --- /dev/null +++ b/betty/spi.c @@ -0,0 +1,35 @@ +/* + * spi.c - serial peripheral interface 0/1 + * + * author: hackbard@hackdaworld.org + * + */ + +#include "spi.h" + +/* + * functions + */ + +void spi1_init(u8 width,u8 type,u8 div) { + + if((width<8)|(width>16)) + width=8; + if(width==16) + width=0; + + div&=0xfe; + if(div<8) + div=8; + + S1SPCR=(1<<2)|(width<<8)|(type<<5); + S1SPCCR=div; +} + +void spi1_send(u16 data) { + + S1SPDR=data; + + while(!(S1SPSR&(1<<7))) + continue; +}