Truyền dữ liệu trong SPI

Một phần của tài liệu TỔNG QUAN VI XỬ LÝ LPC2300 HƯỚNG DẪN SỬ DỤNG BOARD MCB 2300 (Trang 66 - 73)

Hình sau đây là một sơ đồ thời gian để minh họa bốn định dạng truyền dữ liệu khác nhau mà có sẵn với SPI. Sơ đồ thời gian này minh họa một truyền dữ liệu 8-bit duy nhất.

KHOA HỌC & KỸ THUẬT MÁY TÍNH

Đồ án Thiết Kế Luận Lý – GVHD : Nguyễn Quốc Tuấn

Thực hiện : Nguyễn Thanh Bi – Đỗ Minh Chiến Trang 60

Bảng 29 Mối quan hệ giữa dữ liệu SPI và giai đoạn của Clock

CPOL and CPHA settings

First data driven Other data driven Data sampled

CPOL = 0, CPHA = 0 Prior to first SCK risingedge SCK falling edge SCK rising edge

CPOL = 0, CPHA = 1 First SCK rising edge SCK rising edge SCK rising edge

CPOL = 1, CPHA = 0 Prior to first SCK falling edge SCK rising edge SCK rising edge

CPOL = 1, CPHA = 1 First SCK falling edge SCK falling edge SCK rising edge

I.14.3 Địa chỉ thanh ghi

Bảng 30 Địa chỉ thanh ghi trong SPI

Name Description Access Reset

Value

Address

S0SPCR SPI Control Register. This register

controls the operation of the SPI.

R/W 0x00 0xE002 0000

S0SPSR SPI Status Register. This register shows

the status of the SPI.

RO 0x00 0xE002 0004

S0SPDR SPI Data Register. This bi-directional

register provides the transmit and receive data for the SPI. Transmit data is provided to the SPI0 by writing to this register. Data received by the SPI0 can be read from this register.

R/W 0x00 0xE002 0008

S0SPCCR SPI Clock Counter Register. This

register controls the frequency of a master’s SCK0.

R/W 0x00 0xE002 000C

S0SPINT SPI Interrupt Flag. This register contains

the interrupt flag for the SPI interface.

KHOA HỌC & KỸ THUẬT MÁY TÍNH

Đồ án Thiết Kế Luận Lý – GVHD : Nguyễn Quốc Tuấn

Thực hiện : Nguyễn Thanh Bi – Đỗ Minh Chiến Trang 61

I.14.3.1 SPI Control Register (S0SPCR - 0xE002 0000)

S0SPCR thanh ghi điều khiển thiết lập các bit hoạt động của SPI0 như bảng dưới đây. Bảng 31 Mô tả chức năng các bit của thanh ghi S0SPCR

Bit Symbol Value Description Reset

Value

1:0 - - Reserved, user software should not write ones to reserved

bits. The value read from a reserved bit is not defined.

NA

2 BitEnable 0 The SPI controller sends and receives 8 bits of data per

transfer.

0

1 The SPI controller sends and receives the number of bits

selected by bits 11:8.

3 CPHA 0 Clock phase control determines the relationship between

the data and the clock on SPI transfers, and controls when a slave transfer is defined as starting and ending. Data is sampled on the first clock edge of SCK. A transfer starts and ends with activation and deactivation of the SSEL signal.

0

1 Data is sampled on the second clock edge of the SCK. A

transfer starts with the first clock edge, and ends with the last sampling edge when the SSEL signal is active.

4 CPOL 0 Clock polarity control.

SCK is active high.

0

1 SCK is active low.

5 MSTR 0 Master mode select.

The SPI operates in Slave mode.

0

1 The SPI operates in Master mode.

KHOA HỌC & KỸ THUẬT MÁY TÍNH

Đồ án Thiết Kế Luận Lý – GVHD : Nguyễn Quốc Tuấn

Thực hiện : Nguyễn Thanh Bi – Đỗ Minh Chiến Trang 62

when transferred.SPI data is transferred MSB (bit 7) first. 1 SPI data is transferred LSB (bit 0) first.

7 SPIE 0 Serial peripheral interrupt enable.

SPI interrupts are inhibited.

0

1 A hardware interrupt is generated each time the SPIF or

MODF bits are activated.

11:8 BITS - When bit 2 of this registeris 1, this field controls the

number of bits per transfer:

0000

1000 8 bits per transfer 1001 9 bits per transfer 1010 10 bits per transfer 1011 11 bits per transfer 1100 12 bits per transfer 1101 13 bits per transfer 1110 14 bits per transfer 1111 15 bits per transfer 0000 16 bits per transfer

15:12 - - Reserved, user software should not write ones to reserved

bits. The value read from a reserved bit is not defined.

KHOA HỌC & KỸ THUẬT MÁY TÍNH

Đồ án Thiết Kế Luận Lý – GVHD : Nguyễn Quốc Tuấn

Thực hiện : Nguyễn Thanh Bi – Đỗ Minh Chiến Trang 63

I.14.3.2 SPI Status Register (S0SPSR - 0xE002 0004)

S0SPSR thanh ghi điều khiển thiết lập các bit hoạt động của SPI0 như bảng dưới đây. Bảng 32 Mô tả chức năng các bit của thanh ghi S0SPSR

Bit Symbol Description Reset

Value

2:0 - Reserved, user software should not write ones to reserved bits. The value

read from a reserved bit is not defined.

NA

3 ABRT Slave abort. When 1, this bit indicates that a slave abort has occurred. This bit is cleared by reading this register.

0

4 MODF Mode fault. when 1, this bit indicates that a Mode fault error has occurred. This bit is cleared by reading this register, then writing the SPI0 control register.

5 ROVR Read overrun. When 1, this bit indicates that a read overrun has occurred.

This bit is cleared by reading this register.

6 WCOL Write collision. When 1, this bit indicates that a write collision has occurred. This bit is cleared by reading this register, then accessing the SPI data register.

7 SPIF SPI transfer complete flag. When1, this bit indicates when a SPI data transfer is complete. When a master, this bit is set at the end of the last cycle ofthe transfer. When a slave, this bit is set on the last data sampling edge of the SCK. This bit is cleared by first reading this register, then accessing the SPI data register.

Note:this is not the SPI interrupt flag. This flag is found in the SPINT register.

I.14.3.3 SPI Data Register(S0SPDR - 0xE002 0008)

Thanh ghi dữ liệu 2 chiều cung cấp khả năng truyền và nhận cho SPI. Dữ liệu truyền thì được cung cấp nhờ SPI và được viết vào thanh ghi này. Tương tự dữ liệu nhận từ SPI cũng được đọc từ thanh ghi này. Khi một master hoạt động, thanh ghi sẽ bắt đầu việc viết dữ liệu,

KHOA HỌC & KỸ THUẬT MÁY TÍNH

Đồ án Thiết Kế Luận Lý – GVHD : Nguyễn Quốc Tuấn

Thực hiện : Nguyễn Thanh Bi – Đỗ Minh Chiến Trang 64

khi SPIF status được set thì dữ liệu truyền bị block, đồng thời trạng thái thanh ghi sẽ không được đọc nữa.

I.14.3.4 SPI Clock Counter Register (S0SPCCR - 0xE002 000C)

Thanh ghi này điều khiển tần số SCK, đồng thời cho số chu kì PCLK tạo nên 1 clock SPI. Giá trị của thanh ghi này phải luôn luôn là số chẵn dẫn đến bit 0 luon luôn là 0. Đồng thời giá trị của thanh ghi luôn luôn lớn hơn hoặc bằng 8.

I.14.3.5 SPI Test Control Register (SPTCR - 0xE002 0010)

Các bit của thanh ghi SPTCR chỉ nhằm vào mục địch nhất định, không sử động trong các chức năng bình thường. Có thể tham khảo thêm bảng dưới đây.

Bảng 33 Mô tả các bit của thanh ghi SPTCR

Bit Symbol Description Reset

Value

0 - Reserved, user software should not write ones to reserved bits. The value

read from a reserved bit is not defined

NA

7:1 Test SPI test mode. When 0, the SPI operates normally. When 1, SCK will always be on, independent of master mode select, and data availability setting.

0

I.14.3.6 SPI Test Status Register (SPTSR - 0xE002 0014)

Các bit của thanh ghi SPTCR chỉ nhằm vào mục địch nhất định, không sử động trong các chức năng bình thường. Có thể tham khảo thêm bảng dưới đây.

Bảng 34 Mô tả các bit của thanh ghi SPTSR

Bit Symbol Description Reset

Value

2:0 - Reserved, user software should not write ones to reserved bits. The value

read from a reserved bit is not defined.

NA

3 ABRT Slave abort. 0

4 MODF Mode fault.

KHOA HỌC & KỸ THUẬT MÁY TÍNH

Đồ án Thiết Kế Luận Lý – GVHD : Nguyễn Quốc Tuấn

Thực hiện : Nguyễn Thanh Bi – Đỗ Minh Chiến Trang 65

6 WCOL Write collision.

7 SPIF SPI transfer complete flag

I.14.3.7 SPI Interrupt Register (S0SPINT - 0xE002 001C)

Thanh ghi chứa các cờ của interrupt.

I.14.4 Kiến trúc

Hình 30 Sơ đồ khối SPI Khối SPI bao gồm:

 Bộ SPI REGISTER INTERFACE

 Bộ SPI SHIFT REGISTER

 Bộ SPI CLOCK GENERATOR &DETECTOR

 Bộ SPI STATE CONTROL

KHOA HỌC & KỸ THUẬT MÁY TÍNH

Đồ án Thiết Kế Luận Lý – GVHD : Nguyễn Quốc Tuấn

Thực hiện : Nguyễn Thanh Bi – Đỗ Minh Chiến Trang 66

Một phần của tài liệu TỔNG QUAN VI XỬ LÝ LPC2300 HƯỚNG DẪN SỬ DỤNG BOARD MCB 2300 (Trang 66 - 73)