| 
				打卡等级:以坛为家I打卡总天数:224最近打卡:2025-10-31 13:03:41   管理员 
 
	积分20093 
 | 
 
 发表于 2023-5-10 09:58:28
|
显示全部楼层 
| 在内部的ARM开发平台上硬件SWD仿真调试 : SPI1 和 SPI2 的互相传输
 
   
 
 
 #include "main.h"
 #include "delay.h"
 #include "usart1.h"
 #include "SPI.h"
 
 /*********************************************************************************/
 uint8_t aTxBuffer[BUFFERSIZE];
 __IO uint8_t aRxBuffer [BUFFERSIZE];
 __IO uint8_t ubRxIndex = 0;
 __IO uint8_t ubTxIndex = 0;
 
 uint8_t SPI2ubTxBuffer[BUFFERSIZE];
 __IO uint8_t SPI2aRxBuffer [BUFFERSIZE];
 __IO uint8_t SPI2ubTxIndex = 0;
 __IO uint8_t SPI2ubRxIndex = 0;
 
 __IO uint32_t TimeOut = 0;
 __IO uint32_t SendOut = 0;
 
 /*********************************************************************************/
 
 int main(void)
 {
 int i;
 
 /* Initialize Buffer counters */
 SPI2ubRxIndex = 0;
 
 uart1_init(115200);
 SPI1_Config();
 SPI2_Config();
 
 aTxBuffer[0] = 0x55;
 aTxBuffer[1] = 0x01;
 aTxBuffer[2] = 0x02;
 aTxBuffer[3] = 0x03;
 aTxBuffer[4] = 0x04;
 aTxBuffer[5] = 0x05;
 aTxBuffer[6] = 0x06;
 aTxBuffer[7] = 0x07;
 
 printf("STC33F SPI1->SPI2 test.\r\n");
 
 while (1)
 {
 Delay(100);
 if (TimeOut > 0)
 {
 TimeOut--;
 if(TimeOut == 0)
 {
 printf("SPI2 Read: ");
 for(i=0;i<SPI2ubRxIndex;i++)
 {
 printf("%02x ",SPI2aRxBuffer);  //原样打印收到的数据(char)
 //Print1(SPI2aRxBuffer);  //原样打印收到的数据(hex)
 }
 printf("\r\n");
 SPI2ubRxIndex = 0;
 
 printf("SPI1 Read: ");
 for(i=0;i<ubRxIndex;i++)
 {
 printf("%02x ",aRxBuffer);  //原样打印收到的数据(char)
 //Print1(aRxBuffer);  //原样打印收到的数据(hex)
 }
 printf("\r\n");
 ubRxIndex = 0;
 }
 }
 if (SendOut++ > 500)
 {
 SendOut = 0;
 //GPIO_ResetBits(GPIOA,GPIO_Pin_4);
 SPI_SendBuffer(SPI1, aTxBuffer, 8);
 //GPIO_SetBits(GPIOA,GPIO_Pin_4);
 aTxBuffer[7]++;
 }
 }
 
 }
 
 
 
 
 | 
 |