主题中讨论的其他器件:MUX36S08、
工具/软件:
您好:
目前是一名学习 PIC 微控制器的学生。
我正在处理一个工程、但是使用 SPI 通信器件遇到了困难、因此、很荣幸能邀请您提供建议。
首先、提前感谢您的帮助。
当前硬件配置
8 通道 4–20mA 电流传感器输入
每个通道的电流通过 250Ω 电阻器转换为电压(确认工作正常)
使用 MUX36S08 选择通道、该器件通过 MCU 的光耦合器进行控制
所选电压由 ADS8689 读取、ADS8689 通过 SPI 将数字电压发送到 MCU
MCU 通过 RS232 通信将传感器读数发送到终端
使用 MCU pic16f15356
电流终端输出(当前代码)
CH0 = 0
CH1 = 0
CH2 = 0
CH3 = 0
CH4 = 0
CH5 = 0
CH6 = 0
CH7 = 0
所有通道当前都显示值 0。(传感器 4mA 是通道 1 的输入)
我检查过的内容
→250Ω 电阻后传感器的电流输入为 2 μ A 电压
MUX36S08 控制正常工作(确认每通道的电压输出)
整个硬件电源正常运行
通过示波器测量 SPI 信号:
CS:峰峰值 4.6V /平均 2.20V
CLK:峰峰值 4.4V /平均 1.20V
MISO:峰峰值 1.92V /平均 160mV
MOSI:pk-pk 180mV /平均 12.0mV→太弱、疑似问题
ADS8689 引脚 9 (RST) 通过电阻器上拉至 3.3V、但未连接到 MCU
当前问题
尽管 RS232 通信似乎正常工作、但我不确定问题是在于 SPI 通信还是其他地方。
如果您能查看我的代码并告诉我是否需要任何更正或改进、尤其是在 SPI 通信和初始化方面、我将不胜感激。
ADS8689 RST 引脚可能是问题吗?
非常感谢您的时间和支持。
#include <16F15356.h>
#include <stdint.h>
#device ADC=10
#use delay(internal=8MHz)
//Hardware SPI settings
#pin_select SCK1 = PIN_C3
#pin_select SDI1 = PIN_C4 // ADS8689 MISO
#pin_select SDO1 = PIN_C5 // ADS8689 MOSI
#use spi(MASTER, SPI1, MODE=0, BITS=8, BAUD=500000, STREAM=SPI_1)
//RS232 Settings
#pin_select U1TX = PIN_C6
#pin_select U1RX = PIN_C7
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=UART1)
//Chip Select Pin
#define ADS8689_CS PIN_C2
// MUX36S08 Control pin definition
#define MUX_A0 PIN_A0
#define MUX_A1 PIN_A1
#define MUX_A2 PIN_A2
// MUX Channel selection function(0-7)
void MUX36S08_Select(uint8_t ch)
{
output_bit(MUX_A0, bit_test(ch, 0)); // A0
output_bit(MUX_A1, bit_test(ch, 1)); // A1
output_bit(MUX_A2, bit_test(ch, 2)); // A2
}
//ADS conversion value reading function
uint16_t ADS8689_ReadADC()
{
uint8_t msb, lsb;
output_low(ADS8689_CS); delay_us(1);
//Send NOP command
spi_xfer(SPI_1, 0x00);
spi_xfer(SPI_1, 0x00);
spi_xfer(SPI_1, 0x00);
spi_xfer(SPI_1, 0x00);
output_high(ADS8689_CS); delay_us(5);
//Receive transformation values in the next frame
output_low(ADS8689_CS); delay_us(1);
msb = spi_xfer(SPI_1, 0x00); // D[31:24]
lsb = spi_xfer(SPI_1, 0x00); // D[23:16]
spi_xfer(SPI_1, 0x00); // D[15:8] (ignore)
spi_xfer(SPI_1, 0x00); // D[7:0] (ignore)
output_high(ADS8689_CS); delay_us(1);
return ((uint16_t)msb << 8) | lsb;
}
void main()
{
uint8_t ch;
uint16_t adc;
delay_ms(100);
printf("\r\n<MUX36S08 + ADS8689 Start testing>\r\n");
while(TRUE)
{
for(ch = 0; ch < 8; ch++)
{
MUX36S08_Select(ch);
delay_ms(10); //wait for stabilization
adc = ADS8689_ReadADC(); //Read conversion value
printf("CH%u = %lu\r\n", ch, adc);
delay_ms(500);
}
}
}






SPI_MOSI SPI_MISO


SPI_SCK CS_pin


