| công cụ tìm kiếm bảng dữ liệu linh kiện điện tử |
|
AN2945 bảng dữ liệu(PDF) 15 Page - STMicroelectronics |
|
|
|||||||||||||||||||||||||||||
AN2945 bảng dữ liệu(HTML) 15 Page - STMicroelectronics |
|
15 / 18 page ![]() AN2945 Software library Doc ID 15468 15/18 Once you have understood the above operating principle and file organization, for simple applications, you could virtually switch from one product to the other without referring to the reference manual. Let us take a practical example: an SPI peripheral configured in master mode, used to read from/write to an external EEPROM. Figure 4 and Figure 5 below show the initialization code (using the software library) for an STM8S and an STM32 product, respectively. Figure 4. STM8S code example Figure 5. STM32 code example All parameters are identical, and the procedure is similar with two function calls for both configuration and startup. The main difference lies in the way the parameters are passed into the function. STM32 devices use a structure passed by address whereas, for STM8S devices, parameters are passed directly to minimize the amount of RAM needed during the initialization phase (this is necessary with devices with down to 1 Kbyte of RAM). Another difference is the possibility, when using STM32 devices, of specifying the data size (8- or 16-bit) for the SPI. In the above example (Figure 5), the data size is explicitly defined, however, the library is done so that it can be omitted: if this field is not initialized in the structure, the 8-bit data size is used by default to maintain compatibility with STM8S devices. /* --------------- Initialize SPI in Master mode -------------- */ SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_4, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07); /* CRC Polynomial */ /* ------------------------- Enable SPI ----------------------- */ SPI_Cmd(ENABLE); /* ---------------------- SPI1 Master ------------------------- */ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_Init(SPI1, &SPI_InitStructure); /* ----------------------- Enable SPI1 ------------------------ */ SPI_Cmd(SPI1, ENABLE); /* Private variables --------------------------------------- */ SPI_InitTypeDef SPI_InitStructure; |
|
|
Link URL |
| Cho đến nay ALLDATASHEET có giúp ích cho doanh nghiệp của bạn hay không? [ DONATE ] |
Alldatasheet là | Quảng cáo | Liên lạc với chúng tôi | Chính sách bảo mật | Liên kết đến bảng dữ liệu | Trao đổi link | Tìm kiếm theo nhà sản xuất All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |