• slider image 442
  • slider image 492
  • slider image 493
  • slider image 494
  • slider image 495
  • slider image 496
:::


Browsing this Thread:   1 Anonymous Users






Re: 問題:CCS語法 spi通訊
#3
資深會員
資深會員


查看用戶資訊
spi_data_is_in2( )
Syntax: result = spi_data_is_in()
result = spi_data_is_in2()
Parameters: None
Returns: 0 (FALSE) or 1 (TRUE)
Function: Returns TRUE if data has been received over the SPI.
Availability: This function is only available on devices with SPI hardware.
Requires: Nothing
Examples: ( !spi_data_is_in() && input(PIN_B2) );
if( spi_data_is_in() )
data = spi_read();
Example Files: None
Also See: spi_read(), spi_write(), SPI overview
spi_read( )
spi_read2( )
Syntax: value = spi_read (data)
value = spi_read2 (data)
Parameters: data is optional and if included is an 8 bit int.
Returns: An 8 bit int
Function: Return a value read by the SPI. If a value is passed to SPI_READ the data will
be clocked out and the data received will be returned. If no data is ready,
SPI_READ will wait for the data.
If this device is the master then either do a SPI_WRITE(data) followed by a
SPI_READ() or do a SPI_READ(data). These both do the same thing and will
generate a clock. If there is no data to send just do a SPI_READ(0) to get the
clock.
If this device is a slave then either call SPI_READ() to wait for the clock and
data or use SPI_DATA_IS_IN() to determine if data is ready.

Availability: This function is only available on devices with SPI hardware.
Requires: Nothing
Examples: in_data = spi_read(out_data);
Example Files: ex_spi.c
Also See: spi_data_is_in(), spi_write(), SPI overview
spi_write( )
spi_write2( )
Syntax: SPI_WRITE (value)
SPI_WRITE2 (value)
Parameters: value is an 8 bit int
Returns: Nothing
Function: Sends a byte out the SPI interface. This will cause 8 clocks to be generated.
This function will write the value out to the SPI. At the same time data is
clocked out data is clocked in and stored in a receive buffer. SPI_READ may
be used to read the buffer.
Availability: This function is only available on devices with SPI hardware.
Requires: Nothing
Examples: spi_write( data_out );
data_in = spi_read();
Example Files: ex_spi.c
Also See: spi_read(), spi_data_is_in(), SPI overview

spi_xfer( )
Syntax: spi_xfer(data)
spi_xfer(stream, data)
spi_xfer(stream, data, bits)
result = spi_xfer(data)
result = spi_xfer(stream, data)
result = spi_xfer(stream, data, bits)
Parameters: data is the variable or constant to transfer via SPI. The pin used to transfer
data is defined in the DO=pin option in #use spi. stream is the SPI stream to
use as defined in the STREAM=name option in #use spi. bits is how many bits
of data will be transferred.
Returns: The data read in from the SPI. The pin used to transfer result is defined in the
DI=pin option in #use spi.
Function: Transfers data to and reads data from an SPI device.
Availability: All devices with SPI support.
Requires: #use spi
Examples: int i = 34;
spi_xfer(i);
// transfers the number 34 via SPI
int trans = 34, res;
res = spi_xfer(trans);
// transfers the number 34 via SPI
// also reads the number coming in from SPI
Example Files: None
Also See: #USE SPI

發表於: 2008/12/11 16:15
==== ^^ ^^ ====
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 問題:CCS語法 spi通訊
#2
資深會員
資深會員


查看用戶資訊
SPI™ is a fluid standard for 3 or 4 wire, full duplex communications named by Motorola. Most PIC
devices support most common SPI™ modes. CCS provides a support library for taking advantage
of both hardware and software based SPI™ functionality. For software support, see #use spi.
Relevant Functions:
setup_spi(mode)
setup_spi2
Configure the hardware SPI to the specified mode. The mode
configures setup_spi2(mode) thing such as master or slave mode, clock
speed and clock/data trigger configuration.
Note: for devices with dual SPI interfaces a second function, setup_spi2(), is provided to configure
the second interface.
spi_data_is_in() Returns TRUE if the SPI receive buffer has a byte of data.
spi_data_is_in2()
spi_write(value)
spi_write2(value)
Transmits the value over the SPI interface. This will cause the data to
be clocked out on the SDO pin.
spi_read(value)
spi_read2(value)
Performs an SPI transaction, where the value is clocked out on the
SDO pin and data clocked in on the SDI pin is returned. If you just want
to clock in data then you can use spi_read() without a parameter.
Relevant
Preprocessor:
None
Relevant Interrupts:
#int_sspA
#int_ssp2
Transaction (read or write) has completed on the indicated peripheral.
Relevant getenv() Parameters:
SPI Returns TRUE if the device has an SPI peripheral
Example Code:
//configure the device to be a master, data transmitted on H-to-L clock transition
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
spi_write(0x80); //write 0x80 to SPI device
value=spi_read(); //read a value from the SPI device
value=spi_read(0x80); //write 0x80 to SPI device the same time you are reading a value.

發表於: 2008/12/11 16:08
==== ^^ ^^ ====
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


問題:CCS語法 spi通訊
#1
新會員
新會員


查看用戶資訊
我用ccs語法寫spi,要讓PIC18F452和uALFAT-SD溝通,想請問
Q1.SPI_WRITE() 有辦法傳送字元嗎?
Q2.還是有另外的指令?


謝謝

發表於: 2008/12/11 15:05
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------