Hallo, verzweifel...... bin dabei einen MCP3208 AD-Wandler mit einem mega8 anzusprechen, bekomme jedoch einfach nichts zurück...! Ein MCP2515 am SPI läuft ohne Probleme und die Signale am MCP3208 hab ich überprüft, sollten ok sein. Hier die Funktion: int read_mcp3208() { char i=0; char j=0; unsigned int SPIreceived; cbi(PORTD, PIND7); //clear bit Chipselect (pull low) outp(0x06, SPDR); //send bitcombination for read to MCP loop_until_bit_is_set(SPSR, SPIF); // wait until byte is transmitted i=inp(SPDR); j=inp(SPDR); SPIreceived = (i << 8) |j; sbi(PORTD, PIND7); //set bit Chipselect return (j); } Hat vielleicht jemand eine Idee oder weist mich auf die richige Spur?
Er läuft jetzt.
Falls es jemand brauchen kann hier die Funktion (liest Kanal 0):
int read_mcp3208()
{
int SPIreceived=0;
char i=0; j=0; temp=SPCR;
SPCR=0x5F;
cbi(PORTD, PIND7); //clear bit Chipselect (pull low)
outp(0x06, SPDR); //Kanal 0 lesen
while(!(SPSR & 0x80));
outp(0x00, SPDR); //High Byte "takten"
while(!(SPSR & 0x80));
j=inp(SPDR) & 0x0F;
outp(0x00, SPDR); //Low Byte "takten"
while(!(SPSR & 0x80));
i=inp(SPDR);
sbi(PORTD, PIND7); //set bit Chipselect (pull high)
//PORTD7 = SlaveSelect für MCP3208!!
SPIreceived = (j << 8) | i;
SPCR=temp;
return (SPIreceived);
}
Gast
#3301502
danke :-)
Antwort schreiben
Bitte melde dich an, um einen Beitrag zu schreiben.