Thursday, 15 August 2013

avr - ENC28J60 returning wrong(unexpected) values(SOLVED) -



avr - ENC28J60 returning wrong(unexpected) values(SOLVED) -

i'm trying create own library enc28j60. yes, know there several ready utilize libraries out there, thing scratch, understand going on, how works.

so, i'm @ beging , found someting don't understand. first test send rcr command read bank0. i've recived mixed results. on uart(hyperterminal) i'm getting next results back:

usart ready spi ready 1 rcr-erdptl send: 0 "(sending rcr|erdptl = 0 on spi)" 0 11111010 11111010 ok 1 101 101 ok 2 0 0 ok 3 0 0 ok 4 0 0 ok 5 0 0 ok 6 0 0 ok 7 0 0 ok 8 1000 11111010 error 9 101 101 ok 10 11111111 11111111 ok 11 11111 11111 ok 12 110001 11111010 error 13 110011 101 error 14 0 0 ok 15 0 0 ok

the first column byte number or number of register of bank0, sec column value i'm getting enc chip(according datasheet), 3rd tha value should get, , fouth simple check find mismatch.

as can see there 3 values not correspond datasheet. why?

my code following:

#include <define.h> #include <enc28j60.h> #define enc28j60 pb3 #define enc28j61 pb4 #define dummy 0x00 unsigned char i, data, data0[] = {}, data1[] = {}, data2[] = {}, data3[16] = {0b11111010, 0b00000101, 0,0,0,0,0,0,0b11111010,0b00000101,255,0b00011111,0b11111010,0b00000101,0,0}; void enc28j60_cs(void) // enc28j60 select { spi_port &= ~(1<<enc28j60); } void enc28j60_ds(void) // enc28j60 deselect { spi_port |= (1<<enc28j60); } void enc28j61_cs(void) // enc28j60 select { spi_port &= ~(1<<enc28j61); } void enc28j61_ds(void) // enc28j60 deselect { spi_port |= (1<<enc28j61); } void enc28j60_src(void) // scheme reset command (soft reset) { enc28j60_cs(); // enable spiwr(0xff); enc28j60_ds(); // disable _delay_ms(50); } int main(void) { _delay_ms(3000); usart0_init(12); usart0_tx_string("usart ready"); usart0_txd(10); usart0_txd(13); spi_init(); portb ^= 1<<pinb0; usart0_tx_string("spi ready"); usart0_txd(10); usart0_txd(13); enc28j60_ds(); enc28j61_ds(); _delay_ms(250); enc28j60_src(); enc28j61_cs(); // enable spiwr(0xff); enc28j61_ds(); // disable _delay_ms(250); enc28j60_cs(); spiwr(rcr|erdptl); portb ^= 1<<pinb0; usart0_tx_string("1 rcr-erdptl send: "); itoa(rcr|erdptl, stringa, 10); usart0_tx_string(stringa); usart0_txd(10); usart0_txd(13); info = spiwrd(0xff); for(i = 0;i<15;i++) { data0[i] = spiwrd(0xff); } enc28j60_ds(); for(i = 0;i<16;i++) { portb ^= 1<<pinb0; itoa(i, stringa, 10); usart0_tx_string(stringa); usart0_txd(9); itoa(data0[i], stringa, 2); usart0_tx_string(stringa); usart0_txd(9); usart0_txd(9); itoa(data3[i], stringa, 2); usart0_tx_string(stringa); usart0_txd(9); if(data0[i] == data3[i]) { usart0_tx_string("ok"); } else { usart0_tx_string("error"); } usart0_txd(10); usart0_txd(13); } portb |= 1<<pinb0; while(1) { } }

there matter gives me headaches. ha add together spi junk transmission on line 71, because if had not done this, first result twice , rest out of line. according datasheet(section 4.2.1) reading mac or mii registers should dummy byte. what's whit that?

i'm using avr atmega1284p winavr.

it seems problem yet 1 time again in code.

in declaration of variables(data0 2) have not set size of them:

unsigned char i, data, data0[] = {}, data1[] = {}, data2[] = {}, data3[16] = {0b11111010, 0b00000101,0,0,0,0,0,0,0b11111010,0b00000101, 255,0b00011111,0b11111010,0b00000101,0,0};

i should have done this:

unsigned char i, data, data0[16] = {}, data1[16] = {}, data2[16] = {}, data3[16] = {0b11111010, 0b00000101, 0,0,0,0,0,0,0b11111010,0b00000101, 255,0b00011111,0b11111010,0b00000101,0,0};

avr ethernet

No comments:

Post a Comment