 |
 |
View previous topic :: View next topic |
Author |
Message |
songdaegon
Joined: 17 Jun 2025 Posts: 4
|
pic16f15356 ADS8689 SPI Issue |
Posted: Wed Jun 18, 2025 2:22 am |
|
|
Quote: |
Hello,
I am currently a student studying PIC microcontrollers.
I'm working on a project and having difficulties with the SPI communication part, so I’m writing to kindly ask for your advice.
First of all, thank you in advance for your help.
Current Hardware Configuration
8-channel 4–20mA current sensor inputs
Each channel’s current is converted to voltage through a 250Ω resistor (confirmed working)
Channels are selected using a MUX36S08, controlled via photo-couplers from the MCU
The selected voltage is read by an ADS8689, which sends the digital voltage to the MCU via SPI
The MCU sends the sensor readings to the terminal via RS232 communication
Use mcu pic16f15356
Current Terminal Output(current code)
<MUX36S08 + ADS8689 Start testing>
CH0 = 0
CH1 = 0
CH2 = 0
CH3 = 0
CH4 = 0
CH5 = 0
CH6 = 0
CH7 = 0
All channels are currently showing a value of 0.(Sensor 4ma is input to channel 1)
What I’ve Checked
Current input from the sensors → voltage after 250Ω resistor confirmed
MUX36S08 control is working (voltage output per channel confirmed)
Entire hardware power supply is operating normally
SPI signal measurements via oscilloscope:
CS: pk-pk 4.6V / Avg 2.20V
CLK: pk-pk 4.4V / Avg 1.20V
MISO: pk-pk 1.92V / Avg 160mV
MOSI: pk-pk 180mV / Avg 12.0mV → too weak, suspected issue
ADS8689 pin 9(RST) is pulled up to 3.3V with a resistor, but is not connected to the MCU
Current Issue
Although RS232 communication appears to be working, I am not sure if the issue lies in the SPI communication or elsewhere.
I would sincerely appreciate it if you could review my code and let me know if there are any corrections or improvements needed, especially regarding SPI communication and initialization.
Thank you very much for your time and support.
|
Code: |
#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);
}
}
}
|
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19867
|
|
Posted: Wed Jun 18, 2025 7:18 am |
|
|
I suspect your problem is the wiring of the RST pin.
If you look it won't exit the reset state, until this is pulled high, with CS
held low. Now your CS will be floating at the boot up, so this will not happen.
Try adding a large resistor (10KR say), on the CS line, so that it is held
low when the processor starts, and a small capacitor (1nF perhaps), on
the RST pin, so it takes a moment to go high when the power comes on. |
|
 |
songdaegon
Joined: 17 Jun 2025 Posts: 4
|
ADS8689 RST connection |
Posted: Wed Jun 18, 2025 6:00 pm |
|
|
Ttelmah wrote: | I suspect your problem is the wiring of the RST pin.
If you look it won't exit the reset state, until this is pulled high, with CS
held low. Now your CS will be floating at the boot up, so this will not happen.
Try adding a large resistor (10KR say), on the CS line, so that it is held
low when the processor starts, and a small capacitor (1nF perhaps), on
the RST pin, so it takes a moment to go high when the power comes on. |
Quote: |
Thank you very much for your advice.
I'm replying because I have one more question.
Currently, the ADS8689 CS pin is set to LOW by the MCU in the initialization code.
The RST pin of the ADS8689 is pulled up to 3.3V through a 10kΩ resistor, and it is not connected to the MCU.
You mentioned:
“To solve this problem, try adding a large resistor (e.g., 10kΩ) on the CS line to keep it LOW when the processor starts, and a small capacitor (e.g., 1nF) on the RST pin so it rises slowly when power is applied.”
So, I’d like to ask:
How is this approach different from simply setting the CS pin to LOW via MCU code at startup, without the external pull-down resistor?
Also, since the RST pin is already pulled up to 3.3V with a 10kΩ resistor, doesn’t that mean the ADS8689 should already be out of the reset state and operating normally?
Lastly, would it be okay to just connect a large resistor in series with the CS line and keep pulling it LOW through MCU code at startup,
and connect a small capacitor to the RST pin so it rises slowly to HIGH at power-on?
I’d appreciate it if you could explain this in a bit more detail, as I’m still having trouble fully understanding.
Thank you again!
|
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19867
|
|
Posted: Thu Jun 19, 2025 12:07 pm |
|
|
You are missing the point. The proessor takrs _time_ to start after the
supply comes on.The CS line is floating while this happens, the RST line has
risen with the supply, so pulling the CS line low in the code is fa too late......
 |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9479 Location: Greensville,Ontario
|
|
Posted: Thu Jun 19, 2025 1:32 pm |
|
|
hmm... would adding the FUSE 'PUT' ( Power Up Timer ) help ?? |
|
 |
songdaegon
Joined: 17 Jun 2025 Posts: 4
|
|
Posted: Thu Jun 19, 2025 7:04 pm |
|
|
|
|
 |
songdaegon
Joined: 17 Jun 2025 Posts: 4
|
|
Posted: Thu Jun 19, 2025 7:05 pm |
|
|
temtronic wrote: | hmm... would adding the FUSE 'PUT' ( Power Up Timer ) help ?? |
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19867
|
|
Posted: Fri Jun 20, 2025 5:39 am |
|
|
PUT would actually make it worse. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19867
|
|
Posted: Fri Jun 20, 2025 1:16 pm |
|
|
The point is, that the only ways you can guarantee the timings the chip
requires are to either operate both lines from the processor, or to modify
the hardware. |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|