|
|
View previous topic :: View next topic |
Author |
Message |
acidice333
Joined: 14 Oct 2006 Posts: 33
|
32ch multiplexer |
Posted: Wed Jun 27, 2012 1:38 pm |
|
|
18f4550 pic...
I've got this ADG731 32ch multiplexer but I cant seem to get it to work.
I'm not sure if its my programming (probably 'cause I'm not fluent in programming) or my hardware (simple breakout board)
Basically what I'm trying to accomplish is set it to ch13 (pin48 on ADG) so A0 (pic) read from D (pin43 on ADG731)
Ive got something like this and it is probably wrong. I need to use software SPI.
Code: |
/*
sync = c0
din = c1
clk = c2
*/
#use spi(do=pin_c1,clk=pin_c2,enable=pin_c0,enable_active=0,mode=2,bits=8)
setup_adc_ports(AN0);
spi_xfer(0x00001100); //select ch13
while(true) {
set_adc_channel(0);
delay_us(50);
adc = read_adc();
lcd_gotoxy(2,2);
printf(lcd_putc,"a0=%3u ", adc);
}
|
I have ch13 connected to 5v so I can see if my ADC reading works or not but it doesn't. Yes A0 is working, verified by gnding and 5v (0 / 255) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 27, 2012 2:55 pm |
|
|
You didn't show your #fuses or #use delay(). So, I made a test program
with those things and I can now see clock, data, and enable pulses on
my oscilloscope. It's doing SPI mode 2:
Code: |
#include <18F4550.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,CPUDIV1
#use delay(clock=4M)
#use spi(DO=pin_c1,CLK=pin_c2,enable=pin_c0,enable_active=0,mode=2,bits=8)
//======================================
void main(void)
{
while(1)
{
spi_xfer(0x55);
delay_us(100);
}
} |
|
|
|
acidice333
Joined: 14 Oct 2006 Posts: 33
|
|
Posted: Wed Jun 27, 2012 8:24 pm |
|
|
Figured out my problem
I had the bits in the wrong order and I was using 0x0 instead of 0b0 |
|
|
|
|
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
|