1545 views|1 replies

2

Posts

0

Resources
The OP
 

[RVB2601 Creative Application Development] GPIO Simulation SPI Serial Port [Copy link]

 

SPI is a high-speed, full-duplex, synchronous communication bus, and only occupies four wires on the chip pins, saving the chip pins and saving space on the PCB layout, providing convenience. It is mainly used in EEPROM, FLASH, real-time clock, AD converter, and between digital signal processors and digital signal decoders.

When CPHA=0, it means that data is sampled at the first clock edge. When CPOL=1, it means that it is at a high level when idle, and it changes from a high level to a low level, and the first clock edge (falling edge) is sampled. When CPOL=0, it means that it is at a low level when idle, and it changes from a low level to a high level, and the first clock edge (rising edge) is sampled.

When CPHA=1, it means that data is sampled at the second clock edge. When CPOL=1, it means that it is at a high level when idle, and it changes from a high level to a low level and then to a high level, and the second clock edge (rising edge) is sampled. When CPOL=0, it means that it is at a low level when idle, and it changes from a low level to a high level and then to a low level, and the second clock edge (falling edge) is sampled.

Programming:

#ifndef __SOFTSPI_H_
#define __SOFTSPI_H_

//#include "stdint.h"
#include <stdio.h>
#include <string.h>
#include "drv/gpio_pin.h"
#include <drv/pin.h>

#ifndef LSBFIRST
#define LSBFIRST 0
#endif
#ifndef MSBFIRST
#define MSBFIRST 1
#endif

#define SOFTSPI_MODE0 0x00
#define SOFTSPI_MODE1 0x04
#define SOFTSPI_MODE2 0x08
#define SOFTSPI_MODE3 0x0C

#define SOFTSPI_MISO PA7
#define SOFTSPI_MOSI PA25
# define SOFTSPI_SCK PA4

void wait(uint32_t del);
void spi_pinmux_init();
void setBitOrder(uint8_t);
void setDataMode(uint8_t);
uint8_t transfer(uint8_t);
uint16_t transfer16(uint16_t data);
uint16_t read_temp(uint16_t data);
#endif

Testing Procedure:

#include "soft_spi.h"
spi_pinmux_init();
uint32_t t0;
while (1)
{
t0 = transfer16(0xffff);
printf("transfer16 test:%d\n\r",t0);
printf("temprature:%d \n\r",read_temp(0x7fff));
}

Latest reply

The host first introduced the basic situation, and I look forward to the subsequent evaluation.   Details Published on 2022-6-25 21:31
 
 

6593

Posts

0

Resources
2
 

The host first introduced the basic situation, and I look forward to the subsequent evaluation.

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list