intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Hệ thống nhúng - Chương 6

Chia sẻ: Trinh Quang Manh | Ngày: | Loại File: PPT | Số trang:24

57
lượt xem
11
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

In this lesson we will review a couple of communication peripherals available in all the general-purpose devices in the new PIC24 family. • Asynchronous serial communication interfaces UART1 and UART2, • Synchronous serial communication interfaces SPI1 and SPI2, comparing their relative strengths and limitations for use in embedded-control applications.

Chủ đề:
Lưu

Nội dung Text: Hệ thống nhúng - Chương 6

  1. Embedded Systems Hệ thống nhúng Thạc sĩ Lê Mạnh Hải 1
  2. Lesson 6 :Communication Motivation: • Synchronous serial interfaces • Asynchronous serial interfaces • Parallel interfaces • Synchronous communication using the SPI modules • Testing the Read Status Register command • Writing to the EEPROM • Reading the memory contents • A nonvolatile storage library • Testing the new NVM library 2
  3. Flight plan • In this lesson we will review a couple of communication peripherals available in all the general-purpose devices in the new PIC24 family. • Asynchronous serial communication interfaces UART1 and UART2, • Synchronous serial communication interfaces SPI1 and SPI2, comparing their relative strengths and limitations for use in embedded-control applications. 3
  4. Preflight checklist • MPLAB® IDE, • MPLAB C30 compiler and the • MPLAB SIM simulator, • Explorer16 demonstration board and the • MPLAB ICD2 In Circuit Debugger 4
  5. The flight • The PIC24FJ128GA010 offers seven communication peripherals that are designed to assist in all common embedded-control applications. – 2 × the universal asynchronous receiver and transmitters (UARTs) – 2 × the SPI synchronous serial interfaces – 2 × the I2C™ synchronous serial interfaces 5
  6. Synchronous serial interfaces 6
  7. Sharing an SPI bus among multiple masters is theoretically possible but practically very rare. The main advantages of the SPI interface are truly its simplicity and the speed that can be one order of magnitude higher than that of the fastest I2C bus (even without taking into consideration the details 7 of the protocol- specifi c overhead).
  8. Asynchronous serial interfaces The synchronization between transmitter and receiver is obtained by extracting timing information from the data stream itself. Start and stop bits are added to the data and precise formatting (with a fi xed baud rate) 8 allow reliable data transfer.
  9. 9
  10. Parallel interfaces • The Parallel Master Port (PMP) completes the list of basic communication interfaces of the PIC24. • The PMP has the ability to transfer up to 8 bits of information at a time while providing several address lines – Interface directly to most LCD display modules commercially available (alphanumeric and graphic modules with integrated controller) – Compact Flash memory cards (or CF-I/O devices), – printer ports and an almost infi nite number of other basic 8- bit parallel devices available on the market and featuring the standard control signals: −CS, −RD, −WR. 10
  11. Synchronous communication using the SPI modules 11
  12. • The SPI interface is essentially composed of an 8-bit shift register: bits are simultaneously shifted in (MSB fi rst) from the SDI line and shifted out from the SDO line in sync with the clock on pin SCK. 12
  13. SPI Programming 1. #define SPI_MASTER 0x0120 // select 8-bit master mode, CKE=1, CKP=0 2. #define SPI_ENABLE 0x8000 // enable SPI port, clear status 3. #define CSEE _RD12 // select line for Serial EEPROM 4. #define TCSEE _TRISD12 // tris control for CSEE pin 5. // 1. init the PIC24 SPI peripheral 6. TCSEE = 0; // make SSEE pin output 7. CSEE = 1; // de-select the Serial EEPROM (low power standby) 8. SPI2CON1 = SPI_MASTER; // select mode 9. SPI2STAT = SPI_ENABLE; // enable the peripheral 10. // send one byte of data and receive one back at the same time 11. int writeSPI2( int data) 12. { 13. SPI2BUF = data; // write to buffer for TX 14. while( !SPI2STATbits.SPIRBF); // wait for transfer to complete 15. return SPI2BUF; // read the received value 16. }//writeSPI2 13
  14. 25LC256 Memory 1. // 25LC256 Serial EEPROM commands 2. #define SEE_WRSR 1 // write status register 3. #define SEE_WRITE 2 // write command 4. #define SEE_READ 3 // read command 5. #define SEE_WDI 4 // write disable 6. #define SEE_STAT 5 // read status register 7. #define SEE_WEN 6 // write enable 14
  15. 1. /* 2. ** SPI2 demo 3. */ 4. #include 5. // I/O defi nitions 6. #define CSEE _RD12 // select line for Serial EEPROM 7. #define TCSEE _TRISD12 // tris control for CSEE pin 8. // peripheral confi gurations 9. #define SPI_MASTER 0x0120 // select 8-bit master mode, CKE=1, CKP=0 10. #define SPI_ENABLE 0x8000 // enable SPI port, clear status 11. // 25LC256 Serial EEPROM commands 12. #define SEE_WRSR 1 // write status register 13. #define SEE_WRITE 2 // write command 14. #define SEE_READ 3 // read command 15. #define SEE_WDI 4 // write disable 16. #define SEE_STAT 5 // read status register 17. #define SEE_WEN 6 // write enable 18. // send one byte of data and receive one back at the same time 19. int writeSPI2( int data) 20. { 21. SPI2BUF = data; // write to buffer for TX 22. while( !SPI2STATbits.SPIRBF); // wait for transfer to complete 23. return SPI2BUF; // read the received value 15 24. }//writeSPI2
  16. 1. main() 2. { 3. int i; 4. // 1. init the SPI peripheral 5. TCSEE = 0; // make SSEE pin output 6. CSEE = 1; // de-select the Serial EEPROM 7. SPI2CON1 = SPI_MASTER; // select mode 8. SPI2STAT = SPI_ENABLE; // enable the peripheral 9. // 2. Check the Serial EEPROM status 10. CSEE = 0; // select the Serial EEPROM 11. writeSPI2( SEE_STAT); // send a READ STATUS COMMAND 12. i = writeSPI2( 0); // send dummy, read data 13. CSEE = 1; // terminate command
  17. A nonvolatile storage library • /* • ** NVM Access Library • */ • #include • #include “NVM.h” • // I/O defi nitions for PIC24 + Explorer16 demo board • #define CSEE _RD12 // select line for Serial EEPROM • #define TCSEE _TRISD12 // tris control for CSEE pin • // 17
  18. 1. void InitNVM(void) 2. { 3. // init the SPI peripheral 4. TCSEE = 0; // make SSEE pin output 5. CSEE = 1; // de-select the Serial EEPROM 6. SPI2CON1 = SPI_MASTER; // select mode 7. SPI2STAT = SPI_ENABLE; // enable the peripheral 8. }//InitNVM 9. int writeSPI2( int data) 10. {// send one byte of data and receive one back at the same time 11. SPI2BUF = data; // write to buffer for TX 12. while( !SPI2STATbits.SPIRBF); // wait for transfer to complete 13. return SPI2BUF; // read the received value 14. }//WriteSPI2 15. int ReadSR( void) 16. {// Check the Serial EEPROM status register 17. int i; 18. CSEE = 0; // select the Serial EEPROM 19. WriteSPI2( SEE_STAT); // send a READ STATUS COMMAND 20. i = WriteSPI2( 0); // send/receive 21. CSEE = 1; // deselect to terminate command 22. return i; 18 23. } //ReadSR
  19. Testing the new NVM library ** NVM Library test #include #include “NVM.h” main() { int data; // initialize the SPI2 port and CS to access the 25LC256 InitNVM(); // main loop while ( 1) { // read current content of memory location data = iReadNVM( 0x1234); // increment current value Nop(); //
  20. Post-flight briefing In this lesson we have seen briefl y how to use the SPI peripheral module, in its simplest configuration, to gain access to a 25LC256 Serial EEPROM memory, one of the most common types of nonvolatile memory peripherals used in embedded-control applications. 20
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2