一、nuc972 spi
nuc972是一款基于ARM926EJ-S内核的嵌入式高性能开发板,支持SPI接口,可以实现与SPI设备的通信。以下是SPI模式读写的代码示例:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <linux/spi/spidev.h> static const char *dev = "/dev/spidev0.0"; static uint8_t mode = 0; static uint8_t bits = 8; static uint32_t speed = 500000; static uint16_t delay = 0; int main(int argc, char *argv[]) { int fd, ret; uint8_t tx[3]; uint8_t rx[3]; fd = open(dev, O_RDWR); if (fd < 0) { perror("open"); return 1; } ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); if (ret == -1) { perror("can't set spi mode"); return 1; } ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); if (ret == -1) { perror("can't set bits per word"); return 1; } ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); if (ret == -1) { perror("can't set max speed hz"); return 1; } memset(tx, 0, sizeof(tx)); memset(rx, 0, sizeof(rx)); tx[0] = 0x9f; struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, .rx_buf = (unsigned long)rx, .len = 3, .delay_usecs = delay, .speed_hz = speed, .bits_per_word = bits, }; ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); if (ret < 1) { perror("can't send spi message"); return 1; } for (int i = 0; i < 3; i++) { printf("%02x ", rx[i]); } printf("\n"); close(fd); return status; }
以上代码为nuc972读取SPI设备的代码示例,通过SPI接口读取设备数据。其中dev是SPI接口的设备文件名,spi_ioc_transfer结构体中初始化了发送和接收缓冲区,以及SPI的参数。
二、nuc972 8720
nuc972 8720是nuc972系列中一款常用的芯片,以下是用nuc972 8720编写的二进制文件烧写的代码示例:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #define FILENAME "nuc972.bin" #define MEM_DEV "/dev/mem" static unsigned int Nuc_Phy_Addr = 0x00; static unsigned int Nuc_Virt_Addr = 0x00; static unsigned int Nuc_Size = 0x00; int main(int argc, char *argv[]) { int fd, fdbin, ret; unsigned long offset; char *bin_buf; void *mem_ptr; fdbin = open(FILENAME, O_RDONLY); if (fdbin < 0) { printf("open %s error, %s\n", FILENAME, strerror(errno)); return -1; } fd = open(MEM_DEV, O_RDWR | O_SYNC); if (fd < 0) { printf("open %s error, %s\n", MEM_DEV, strerror(errno)); return -1; } bin_buf = malloc(BIN_SIZE); if (bin_buf == NULL) { printf("malloc failed\n"); return -1; } memset(bin_buf, 0, BIN_SIZE); ret = read(fd, bin_buf, BIN_SIZE); if (ret != BIN_SIZE) { printf("read %s error, %s\n", FILENAME, strerror(errno)); return -1; } mem_ptr = mmap(0, BIN_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, Nuc_Phy_Addr); if (mem_ptr == MAP_FAILED) { printf("mmap failed, %s\n", strerror(errno)); return -1; } memcpy(mem_ptr + Nuc_Virt_Addr, bin_buf, BIN_SIZE); munmap(mem_ptr, BIN_SIZE); close(fd); close(fdbin); return 0; }
以上代码为将二进制文件nuc972.bin烧写到nuc972 8720芯片的程序中。代码通过打开/dev/mem设备,然后将nuc972.bin读入内存缓冲区,再将其映射到nuc972 8720的物理地址上,修改虚拟地址的内容为bin_buf。最后释放映射区和关闭设备文件。
三、NUC972DF71YC
NUC972DF71YC是一款低功耗、高性能的嵌入式开发板。以下是通过NUC972DF71YC串口的代码示例:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <termios.h> static int fd; int open_port(void) { fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY); if (fd < 0) { printf("open ttyS1 failed\n"); return -1; } struct termios options; tcgetattr(fd, &options); options.c_cflag = B115200 | CS8 | CLOCAL | CREAD; options.c_iflag = 0; options.c_oflag = 0; options.c_lflag = 0; tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &options); return fd; } int main(int argc, char *argv[]) { open_port(); int ret; char *send_buf = "hello from nuc972\r\n"; char recv_buf[50]; ret = write(fd, send_buf, strlen(send_buf)); printf("send: %s\n", send_buf); usleep(10000); ret = read(fd, recv_buf, sizeof(recv_buf)); printf("recv: %s\n", recv_buf); close(fd); return 0; }
以上代码为nu972串口通信的代码示例,程序中定义了UART的属性,并利用串口传输数据。首先打开串口设备文件,通过tcgetattr()函数获取串口属性,再通过tcsetattr()函数设置串口属性。然后通过read()和write()函数进行串口通信。最后关闭串口设备文件。
四、NUC972什么时候发布
NUC972是由国内知名芯片设计公司——翱捷科技开发的具有国际水平的高性能芯片。该芯片于2015年12月发布,经过多年的市场检验,已经成为嵌入式领域中的重要芯片之一。
原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/185875.html