📄 spi.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML><HEAD> <META NAME="GENERATOR" CONTENT="langdoc 1.0.1"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <TITLE> Library for Serial Port Interface module: SPI </TITLE> </HEAD> <BODY> <TABLE BORDER="1" WIDTH="100%" CELLPADDING="6"> <TR> <TD ALIGN=CENTER VALIGN=MIDDLE BGCOLOR=BLUE> <H1> <FONT COLOR="#FFFFFF"> Library for Serial Port Interface module: SPI </FONT> </H1> </TD> </TR> </TABLE><P ALIGN=RIGHT> <I> Copyright (c) 2003 Atmel</I> </P><H2> Library Usage </H2><H3> Package Description </H3><H4> Overview </H4>This package provides low level routines to send and receive data withthe SPI hardware controller of ATMEL AT89C51CC03 products.<P><H4> Configuration </H4>This driver does not need special configuration.<P>Before using the low level transmission format in master or slave mode, the functionsspi_master_init() or spi_slave_init() should be called.<P><PRE>NOTES-----In master mode to transmit one or several (n) data bytes, the low level functionspi_transmit_byte(data) should be called n times and all transmission should be closedwith the spi_get_data() function.<P>Example when for a tree bytes spi transmission:spi_master_init(0,1,1,8); //SPI init CPOL=0, CPHA=1, SSDIS=1 bitrate=Fper/8spi_transmit_byte(0xAA);spi_transmit_byte(0x55);spi_transmit_byte(0xAA);spi_get_data();</PRE><H3> Package Summary </H3><H4> Constants </H4><PRE></PRE><H4> Global Variables </H4><PRE></PRE><H4> Macros </H4><PRE></PRE><H4> Functions </H4><PRE><A HREF="#spi_get_data">spi_get_data</A> <A HREF="#spi_interrupt">spi_interrupt</A> <A HREF="#spi_master_init">spi_master_init</A> <A HREF="#spi_put_data">spi_put_data</A> <A HREF="#spi_set_speed">spi_set_speed</A> <A HREF="#spi_slave_init">spi_slave_init</A> <A HREF="#spi_transmit_burst_it">spi_transmit_burst_it</A> <A HREF="#spi_transmit_burst_polling">spi_transmit_burst_polling</A> <A HREF="#spi_transmit_byte">spi_transmit_byte</A> </PRE><H3> Files List </H3><UL><LI><B><A NAME="spi_drv.c"></A> spi_drv.c</B><BR></LI><UL>spi library low level functions (init, receive and send functions) and global variables declarations to use with user software application</UL><LI><B><A NAME="spi_drv.h"></A> spi_drv.h</B><BR></LI><UL>spi lib header file</UL></UL><H3> Included Files </H3><UL><LI><B>config.h </B><BR></LI><LI><B><A HREF="#spi_drv.h">spi_drv.h</A> </B><BR></LI></UL><H2> Constant Macros </H2><H2> Global Variables </H2><H2> Function Macros </H2><H2> Functions </H2><A NAME="spi_get_data"></A><H3> spi_get_data </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>unsigned char <A HREF="#spi_get_data">spi_get_data</A> ( ) </PRE></TD></TABLE><P>Return the content of the spi data register<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: byte received </PRE></TD></TABLE><H4> Note </H4><P>This function performs an active wait polling<HR><A NAME="spi_interrupt"></A><H3> spi_interrupt </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#spi_interrupt">spi_interrupt</A> ( void ) interrupt IRQ_SPI </PRE></TD></TABLE><P>spi - interruption program for serial transmission ( Master and Slave mode )<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>*spi_string_ptr: the string which must be sendspi_nb_data: number of data to sendreturn: none</PRE></TD></TABLE><HR><A NAME="spi_master_init"></A><H3> spi_master_init </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#spi_master_init">spi_master_init</A> ( bit cpol , bit cpha , bit ssdis , Uchar speed ) </PRE></TD></TABLE><P>Initialize the spi module in master mode<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>cpol: bit CPOL valuecpha: bit CPHA valuessdis: bit SSDIS valuespeed: Uchar spi speed ratio transmission Vs Fper return: none</PRE></TD></TABLE><H4> Example </H4><PRE>spi_master_init(0,1,1,4); // init spi in mater mode with CPOL=0, CPHA=1,// SSDIS=1 and bitrate=Fper/4</PRE><HR><A NAME="spi_put_data"></A><H3> spi_put_data </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#spi_put_data">spi_put_data</A> ( unsigned char to_transmit ) </PRE></TD></TABLE><P>Send a data byte to the spi interface<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: none</PRE></TD></TABLE><H4> Note </H4><P>This function should be use in spi slave mode to load spi data registerwith the next data to be transmited in slave mode<HR><A NAME="spi_set_speed"></A><H3> spi_set_speed </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>bit <A HREF="#spi_set_speed">spi_set_speed</A> ( unsigned char ratio ) </PRE></TD></TABLE><P>Configure the baud rate of the spi, set CR2, CR1, CR0<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: bit: status </PRE></TD></TABLE><H4> Note </H4><P>This function is use only in spi master mode<HR><A NAME="spi_slave_init"></A><H3> spi_slave_init </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#spi_slave_init">spi_slave_init</A> ( bit cpol , bit cpha , bit ssdis ) </PRE></TD></TABLE><P>Initialize the spi module in slave mode<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>cpol: bit CPOL valuecpha: bit CPHA valuessdis: bit SSDIS valuereturn: none</PRE></TD></TABLE><H4> Example </H4><PRE>spi_master_init(0,1,1); // init spi in mater mode with CPOL=0, CPHA=1, SSDIS=1</PRE><HR><A NAME="spi_transmit_burst_it"></A><H3> spi_transmit_burst_it </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>bit <A HREF="#spi_transmit_burst_it">spi_transmit_burst_it</A> ( Uchar * string_ptr , Uchar data_nb ) </PRE></TD></TABLE><P>Initialize an spi tranfert in interrupt modeWorks in interrupt modeIf a current transfert is on going, the function returns '0'<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>*string_ptr: the string which must be senddata_nb: number of data to sendreturn: bit</PRE></TD></TABLE><H4> Note </H4><P>This function can be used in slave or master mode<HR><A NAME="spi_transmit_burst_polling"></A><H3> spi_transmit_burst_polling </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>void <A HREF="#spi_transmit_burst_polling">spi_transmit_burst_polling</A> ( unsigned char * ptr_buf , unsigned char nb_data ) </PRE></TD></TABLE><P>Transmit a data string throught the spi interface in polling mode<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>nb_data: number of data to sendreturn: none </PRE></TD></TABLE><H4> Note </H4><P>This function performs an active wait polling<HR><A NAME="spi_transmit_byte"></A><H3> spi_transmit_byte </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>unsigned char <A HREF="#spi_transmit_byte">spi_transmit_byte</A> ( unsigned char tx_data ) </PRE></TD></TABLE><P>Send and receive a byte with spi interface<P><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#FFD0D0" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>return: byte received </PRE></TD></TABLE><H4> Note </H4><P>If a current spi transfert is on going, the function performs an active wait polling on spi event.This function can be used both in slave and master mode<HR></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -