I'm using the MCP2515. I'd like to use the DAC as it will work perfect for my project. Being able to use multiple SPI devices on the same PIC is a nice feature. If using interrupts, are there other issues to consider with using the CS lines?
I'm using the MCP2515. I'd like to use the DAC as it will work perfect for my project. Being able to use multiple SPI devices on the same PIC is a nice feature. If using interrupts, are there other issues to consider with using the CS lines?
Hi,
In the case of MCP2515 and MCP4911 there really can't be any conflicts since only one of them actually puts data out on the MISO line.
With SPI it's always the master (the PIC in this case) that initiates and "drives" the communication with the slave devices, the slave devices can not start transfering on their own. The INT\ pin on the MCP2515 - for example - is used to let the master device know that the slave needs attention. If the master is in the middle of a "converstation" with another device it's up to the master to decide if it should answer the slaves request for attention or wait (and possibly risk missing something important).
Again, with SPI there's one master (the PIC in this case) and, at least, one slave. The master provides the clock and only the slave whos CS\ line is active (low) will listen to data being put out by the master on the SDI/MOSI line and only the slave whos CS\ line is active will (or at least should) put data out on the SDO/MISO line. A SPI slave device can never "send" anything on its own since the clock to actually shift data out on the SDO/MISO line is generated by the master.
/Henrik.
Great information, Henrik. Thanks for the detailed explanation. More questions to follow soon.
Roadblock #1.
I got a hold of a MCP4911E. If I understand the datasheet correctly, this chip has literally one command that is a word sized variable. I'm using the internal oscillator on a 16F690. What am I doing wrong?
Code:' ================================================================ CS VAR PORTC.7 CLK VAR PORTC.1 SDI VAR PORTC.0 LDAC VAR PORTC.2 ' ' ================================================================ X VAR WORD 'GENERAL TIMER ' PROGRAM INIT ' ================================================================ ' MAIN LOOP ' ================================================================ CS=1 X=0 MAIN: TOGGLE PORTB.4 GOSUB SEND_VOLTS PAUSE 100 GOTO MAIN ' ' ================================================================ SEND_VOLTS: TOGGLE PORTB.7 TOGGLE PORTB.5 TOGGLE PORTB.6 TOGGLE PORTB.7 LOW CS LOW LDAC PAUSE 100 SHIFTOUT SDI,CLK,0, [%011100111110] HIGH CS 'HIGH LDAC RETURN
Hi,
Never used it and don't have access to one to try with.
BUT the datasheet says that all write operations are 16 bits, 4 configuration bits followed by 12 databits where the 2 least significant bits doesn't matter for the 10-bit MCP4911. You're only sending 12 bits.
You're using MODE 0, which accordning to the manual shifts data out LSB first while the MCP4911 expects MSB first. Doesn't really matter as long as you remember to put the bits in the correct order before sending them. SHIFTOUT does 8 bits by default, if you want anything else (up to 32) you need to specify that.
Also, make sure you don't have any analog functions (comparator, ADC) mutliplexed onto the pins you're using. They are usually, but not always, turned on by default - always double check if you haven't already.
I'd probably try:/Henrik.Code:LOW CS SHIFTOUT SDI, CLK, 1, [%0011010101010100\16] HIGH CS LOW LDAC PAUSEUS 100 HIGH LDAC
I'm not getting anything. This is the entire program. Do I need to configure the SSPSTAT register or one that I missed?
Code:include "modedefs.bas" ' REGISTERS AND PINOUT ( 1 = IN; 0 = OUT ) OPTION_REG = %10000000 'PORT A&B Pull-Ups disabled (look WPUA & WPUB) ANSEL = %00000000 'Disable analog inputs Channels 0 to 7 ANSELH = %00000000 'Disable analog inputs Channels 8 to 11 WPUB = %00000000 'Disable weak pull-ups ADCON0 = %00000000 'A/D Module is OFF CM1CON0 = %00000000 'Comparator1 Module is OFF CM2CON0 = %00000000 'Comparator2 Module is OFF INTCON = %00000000 'INTerrupts CONtrol TRISA = %00000000 'Set Input/Output (0 to 5) PORTA = %00000000 'Ports High/Low (0 to 5) TRISB = %00000000 'Set Input/Output (4 to 7) PORTB = %00000000 'Ports High/Low (4 to 7) TRISC = %00000000 'Set Input/Output (0 to 7) PORTC = %00000000 'Ports High/Low (0 to 7) ' ALIAS & MODIFIERS ' ================================================================ CS VAR PORTC.7 CLK VAR PORTC.1 SDI VAR PORTC.0 LDAC VAR PORTC.2 ' VARIABLES & COSTANTS ' ================================================================ X VAR WORD 'GENERAL TIMER ' ' ================================================================ ' MAIN LOOP ' ================================================================ CS=1 X=0 HIGH LDAC MAIN: TOGGLE PORTB.4 GOSUB SEND_DATA PAUSE 1000 GOTO MAIN ' SUB - ROTINES ' ================================================================ SEND_DATA: TOGGLE PORTB.7 TOGGLE PORTB.5 TOGGLE PORTB.6 TOGGLE PORTB.7 LOW CS SHIFTOUT SDI, CLK, 1,[%1001111111111111/16] high cs LOW LDAC PAUSE 10 HIGH LDAC RETURN
Hi,
SHIFTIN/SHIFTOUT are bit-banged commands and does NOT use the SSP/MSSP module so you don't need to set that up. There are no "high level" PBP commands to do SPI (or I2C) with the SSP/MSSP module so you'll need to "drive it" manually - which isn't that hard. But again, since you're using SHIFTOUT it doesn't matter.
Right now you're sending MSB first - which is great. But the very first bit (Bit 15) you're sending is '1' which, if you look at the datasheet, means 'Ignore this command'. So, if everything else is alright, it should do exactly what you're seeing - nothing.
From the datasheet:Do you have a scope or logic analyzer you can use to verify that the pins are doing what they should?bit 15
0 = Write to DAC register
1 = Ignore this command
bit 14 BUF: VREF Input Buffer Control bit
1 = Buffered
0 = Unbuffered
bit 13 GA: Output Gain Selection bit
1 = 1x (VOUT = VREF * D/4096)
0 = 2x (VOUT = 2 * VREF * D/4096)
bit 12 SHDN: Output Shutdown Control bit
1 = Active mode operation. VOUT is available.
0 = Shutdown the device. Analog output is not available. VOUT pin is connected to 500 ktypical)
bit 11-0
D110: DAC Input Data bits. Bit x is ignored.
/Henrik.
Bookmarks