30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

the SPI receive buffer contains any new data that is yet to be read as<br />

indicated by the SPIxSTAT bit. This bit is cleared by<br />

hardware when the data is read from the buffer.<br />

Source File: DataRdySPI1.c<br />

DataRdySPI2.c<br />

Code Example: while(DataRdySPI1());<br />

ReadSPI1<br />

ReadSPI2<br />

Description: This function reads the content of the SPI Receive Buffer<br />

(SPIxBUF)<br />

register.<br />

Include: spi.h<br />

Prototype: unsigned int ReadSPI1(void);<br />

unsigned int ReadSPI2(void);<br />

Arguments: None<br />

Return Value: This function returns the content of Receive Buffer (SPIxBUF)<br />

register.<br />

If a value of ‘-1’ is returned, it indicates that there is no data to be read<br />

from the SPI buffer.<br />

Remarks: This function returns the content of the Receive Buffer register.<br />

If 16-bit communication is enabled, the data in the SPIxRBF register is<br />

returned.<br />

If 8-bit communication is enabled, then the lower byte of SPIxBUF is<br />

returned.<br />

The SPIxBUF is read only if it contains any data as indicated by the<br />

SPISTATbit. Otherwise, a value of ‘-1’ is returned.<br />

Source File: ReadSPI1.c<br />

ReadSPI2.c<br />

Code Example: unsigned int RX_data;<br />

RX_data = ReadSPI1();<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

DS51456B-page 160<br />

WriteSPI1<br />

WriteSPI2<br />

2004 Microchip Technology Inc.<br />

Description: This function writes the data to be transmitted into the Transmit<br />

Buffer<br />

(SPIxBUF) register.<br />

Include: spi.h<br />

PRI_PRESCAL_64_1<br />

config2 này chứa các thông số phải được cấu hình trong<br />

SPIxSTAT đăng ký theo quy định dưới đây:<br />

SPI Enable / Disable<br />

SPI_ENABLE<br />

SPI_DISABLE<br />

SPI hoạt động chế độ Idle<br />

SPI_IDLE_CON<br />

SPI_IDLE_STOP<br />

Nhận rõ ràng tràn cờ bit<br />

SPI_RX_OVFLOW_CLR<br />

Trở lại giá trị: Không<br />

Bình luận: chức năng này khởi tạo các mô-đun SPI và thiết lập chế độ nhàn rỗi<br />

hoạt động.<br />

Source File: OpenSPI1.c<br />

OpenSPI2.c<br />

Mã số Ví dụ: config1 = FRAME_ENABLE_OFF &<br />

FRAME_SYNC_OUTPUT &<br />

ENABLE_SDO_PIN &<br />

SPI_MODE16_ON &<br />

SPI_SMP_ON &<br />

SPI_CKE_OFF &<br />

SLAVE_SELECT_ENABLE_OFF &<br />

CLK_POL_ACTIVE_HIGH &<br />

MASTER_ENABLE_ON &<br />

SEC_PRESCAL_7_1 &<br />

PRI_PRESCAL_64_1;<br />

config2 = SPI_ENABLE &<br />

SPI_IDLE_CON &<br />

SPI_RX_OVFLOW_CLR OpenSPI1 (config1,<br />

config2);<br />

OpenSPI1 (Tiếp theo)<br />

OpenSPI2<br />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ<br />

DS51456B trang 162 2004 Microchip Technology Inc<br />

putsSPI1<br />

putsSPI2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!