Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: W5100 vs ENC28J60 on: February 11, 2014, 09:23:53 am
Since no one answered the first question, I will go ahead.

- The first and most important difference (and the reason of the prices) is the speed. The ENC28J60 supports up to Ethernet speed (10Mbps), and the W5100 supports fast Ethernet speed (100 Mbps). You can confirm this with the chip package (SPDIP is a  through hole package and this are made for slow technologies). This is on the Ethernet side, but on the microcontroller side (Arduino) this is different and this could mean a disadvantage for the W5100. I will explain this below.

- Another difference is the control interface. The ENC28J60 only have SPI (serial) interface to communicate with a microcontroller, but the W5100 have also a parallel interface (instead of accessing just one bit at a time, you can have a whole word i.e. 8 bits). If you're going to use the Arduino Ethernet library this is meaningless because the Arduino library use only the serial interface (SPI).

- The W5100 has four sockets for communication,  this means that you can manage up to four independent communications (different IPs, different computers, etc), but the ENC28J60 has only one socket.

- At last but not least (in fact this difference is very important) the ENC28J60 has a variable size SPI stream up to 16 bits (could be 8 bits also), but the W5100 has a fixed size stream of 32 bits. Both chips use one byte of data. This means, if both chips has the same clock, the W5100 will take more time to transmit just one byte, and if you are transmitting several bytes of data, this difference will be incremented.

- Instead of the difference in the SPI stream, the W5100 SPI clock (up to 14 MHz) can be faster than the ENC28J60 (up to 10 MHz).

These are just the major differences.
2  Products / Arduino Due / Re: WM8731 codec in Arduino Due (SPI and Wire libraries) on: May 01, 2013, 06:18:24 pm
Sorry, the code above isn't readable. Here it is again

Code:
#include <Wire.h>
#include <SPI.h>

#define LINVOL 23
#define RINVOL 23
#define LHPVOL 121
#define RHPVOL 121
#define ADCHPD 0
#define SIDEATT 0
#define SIDETONE 0
#define DACSEL 1
#define BYPASS 0
#define INSEL 0
#define MUTEMIC 1
#define MICBOOST 0
#define SAMPLE_RATE 44

volatile boolean l;

unsigned int temp = 0;
int temp_spi[4];

//TC1 ch 0
void TC3_Handler()
{
        TC_GetStatus(TC1, 0);

        temp = random(65535);
        temp_spi[0] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
        temp_spi[1] = SPI.transfer(10,lowByte(temp),SPI_CONTINUE);
        temp_spi[2] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
        temp_spi[3] = SPI.transfer(10,lowByte(temp),SPI_LAST);
        Serial.println(temp_spi[0]);
        Serial.println(temp_spi[1]);
        Serial.println(temp_spi[2]);
        Serial.println(temp_spi[3]);
}

void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
        pmc_set_writeprotect(false);
        pmc_enable_periph_clk((uint32_t)irq);
        TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
        uint32_t rc = VARIANT_MCK/128/frequency; //128 because we selected TIMER_CLOCK4 above
        TC_SetRA(tc, channel, rc/2); //50% high, 50% low
        TC_SetRC(tc, channel, rc);
        TC_Start(tc, channel);
        tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS;
        tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS;
        NVIC_EnableIRQ(irq);
}

void AudioCodec_init() {
        randomSeed(analogRead(0));
        SPI.begin(10);
        SPI.setBitOrder(MSBFIRST);
        SPI.setClockDivider(10,21); // select to ss pin 10, 4 MHz
        SPI.setDataMode(10,SPI_MODE0);
       
        // setup i2c pins and configure codec
        // the new Wire library has trouble with 0x00, so (uint8_t) is added
        // To change the Wire interface speed, go to:
        // <path_from_arduino>\hardware\arduino\sam\libraries\Wire\Wire.h
        // and change the parameters TWI_CLOCK, RECV_TIMEOUT and XMIT_TIMEOUT
        // to the desire frequency.
        int temp_wire1;
        int temp_wire2;
       
        Wire.begin();
        Wire.beginTransmission(0x1a);
        Wire.write(0x0c); // power reduction register
        Wire.write((uint8_t)0x00); // turn everything on
        temp_wire1 = Wire.endTransmission();
       
        Wire.beginTransmission(0x1a);
        Wire.write(0x0e); // digital data format
        Wire.write(0x03); // 16b SPI mode
        temp_wire2 = Wire.endTransmission();
       
        Serial.println(temp_wire1);
        Serial.println(temp_wire2);
       
        Wire.beginTransmission(0x1a);
        Wire.write((uint8_t)0x00); // left in setup register
        Wire.write((uint8_t)LINVOL);
        Wire.endTransmission();
       
        Wire.beginTransmission(0x1a);
        Wire.write(0x02); // right in setup register
        Wire.write((uint8_t)RINVOL);
        Wire.endTransmission();
       
        Wire.beginTransmission(0x1a);
        Wire.write(0x04); // left headphone out register
        Wire.write((uint8_t)LHPVOL);
        Wire.endTransmission();
       
        Wire.beginTransmission(0x1a);
        Wire.write(0x06); // right headphone out register
        Wire.write((uint8_t)RHPVOL);
        Wire.endTransmission();
       
        Wire.beginTransmission(0x1a);
        Wire.write(0x0a); // digital audio path configuration
        Wire.write((uint8_t)ADCHPD);
        Wire.endTransmission();
       
        Wire.beginTransmission(0x1a);
        Wire.write(0x08); // analog audio pathway configuration
        Wire.write((uint8_t)((SIDEATT << 6)|(SIDETONE << 5)|(DACSEL << 4)|(BYPASS << 3)|(INSEL << 2)|(MUTEMIC << 1)|(MICBOOST << 0)));
        Wire.endTransmission();
       
        Wire.beginTransmission(0x1a);
        Wire.write(0x10); // clock configuration
        #if SAMPLE_RATE == 88
          Wire.write(0xbc);
        #elif SAMPLE_RATE == 44
          Wire.write(0xa0);
        #elif SAMPLE_RATE == 22
          Wire.write(0xe0);
        #elif SAMPLE_RATE == 8
          Wire.write(0xac);
        #elif SAMPLE_RATE == 2
          Wire.write(0xce);
        #endif
        Wire.endTransmission();
     
        Wire.beginTransmission(0x1a);
        Wire.write(0x12); // codec enable
        Wire.write(0x01);
        Wire.endTransmission();
       
}

void setup(){
 
        Serial.begin(9600);
        AudioCodec_init();
        startTimer(TC1, 0, TC3_IRQn, 44100); //startTimer(TC1, 0, TC3_IRQn, 44100); //TC1 channel 0, the IRQ for that channel and the desired frequency
}

void loop(){
}
3  Products / Arduino Due / WM8731 codec in Arduino Due (SPI and Wire libraries) on: May 01, 2013, 06:15:19 pm
Hi,

I was trying to make this board (Audio Codec Board from MikroElektronika) working, but by the moment it doesn't.

So this board use two serial interfaces, one "two wire" interface (compatible with I2C, this should work with the Wire library) for the chip configuration, and another interface for the data transmission (SPI protocol should work).

I used two sources for my code, the library from the "Codec Shield" that Sparkfun sells and the example that MikroElektronika brings in their website (example for PIC). So the AudioCodec_init function initializes both interfaces (the I2C only works inside the function).

The Wire library by default works at 100 KHz I think (at least with the other Arduinos), the device address is 0x1a, first I send the register address then the data. For the first two registers I read the return of the endTransmission function and it always return "2". According to the documentation this should be an error, but I found on the internet that this is a bug, that this function only returns the number of bytes sent and I confirmed this with the source code of the library, so actually the "2" returned is correct. This and the return of the write function (that I also checked and it returns "1" that is alright) are the only source of feedback for this library.

The SPI library is configured for the pin 10, MSB first, clock divider of 21 and in SPI_MODE0 (I am not sure if this mode of operation is correct, I just copied it from the "Codec Shield" library). Now, the feedback for this interface is the data read from the chip. This data is always FF.

So this is the code:

Code:
#include <[color=#CC6600]Wire[/color].h>
#include <[color=#CC6600]SPI[/color].h>

#define LINVOL 23
#define RINVOL 23
#define LHPVOL 121
#define RHPVOL 121
#define ADCHPD 0
#define SIDEATT 0
#define SIDETONE 0
#define DACSEL 1
#define BYPASS 0
#define INSEL 0
#define MUTEMIC 1
#define MICBOOST 0
#define SAMPLE_RATE 44

volatile [color=#CC6600]boolean[/color] l;

[color=#CC6600]unsigned[/color] [color=#CC6600]int[/color] temp = 0;
[color=#CC6600]int[/color] temp_spi[4];

[color=#7E7E7E]//TC1 ch 0[/color]
[color=#CC6600]void[/color] TC3_Handler()
{
        TC_GetStatus(TC1, 0);

        temp = [color=#CC6600]random[/color](65535);
        temp_spi[0] = [color=#CC6600]SPI[/color].transfer(10,[color=#CC6600]highByte[/color](temp),[color=#006699]SPI_CONTINUE[/color]);
        temp_spi[1] = [color=#CC6600]SPI[/color].transfer(10,[color=#CC6600]lowByte[/color](temp),[color=#006699]SPI_CONTINUE[/color]);
        temp_spi[2] = [color=#CC6600]SPI[/color].transfer(10,[color=#CC6600]highByte[/color](temp),[color=#006699]SPI_CONTINUE[/color]);
        temp_spi[3] = [color=#CC6600]SPI[/color].transfer(10,[color=#CC6600]lowByte[/color](temp),SPI_LAST);
}

[color=#CC6600]void[/color] startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
        pmc_set_writeprotect([color=#CC6600]false[/color]);
        pmc_enable_periph_clk((uint32_t)irq);
        TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
        uint32_t rc = VARIANT_MCK/128/frequency;
        TC_SetRA(tc, channel, rc/2);
        TC_SetRC(tc, channel, rc);
        TC_Start(tc, channel);
        tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS;
        tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS;
        NVIC_EnableIRQ(irq);
}

[color=#CC6600]void[/color] AudioCodec_init() {
        [color=#CC6600]randomSeed[/color]([color=#CC6600]analogRead[/color](0));
        [color=#CC6600]SPI[/color].[color=#CC6600]begin[/color](10);
        [color=#CC6600]SPI[/color].setBitOrder([color=#006699]MSBFIRST[/color]);
        [color=#CC6600]SPI[/color].[color=#CC6600]setClockDivider[/color](10,21); [color=#7E7E7E]// select to ss pin 10, 4 MHz[/color]
        [color=#CC6600]SPI[/color].setDataMode(10,SPI_MODE0);
        
        [color=#CC6600]int[/color] temp_wire1;
        [color=#CC6600]int[/color] temp_wire2;
        
        [color=#CC6600]Wire[/color].[color=#CC6600]begin[/color]();
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x0c); [color=#7E7E7E]// power reduction register[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color]((uint8_t)0x00); [color=#7E7E7E]// turn everything on[/color]
        temp_wire1 = [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x0e); [color=#7E7E7E]// digital data format[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x03); [color=#7E7E7E]// 16b SPI mode[/color]
        temp_wire2 = [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](temp_wire1);
        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](temp_wire2);
        
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color]((uint8_t)0x00); [color=#7E7E7E]// left in setup register[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color]((uint8_t)LINVOL);
        [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x02); [color=#7E7E7E]// right in setup register[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color]((uint8_t)RINVOL);
        [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x04); [color=#7E7E7E]// left headphone out register[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color]((uint8_t)LHPVOL);
        [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x06); [color=#7E7E7E]// right headphone out register[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color]((uint8_t)RHPVOL);
        [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x0a); [color=#7E7E7E]// digital audio path configuration[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color]((uint8_t)ADCHPD);
        [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x08); [color=#7E7E7E]// analog audio pathway configuration[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color]((uint8_t)((SIDEATT << 6)|(SIDETONE << 5)|(DACSEL << 4)|(BYPASS << 3)|(INSEL << 2)|(MUTEMIC << 1)|(MICBOOST << 0)));
        [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x10); [color=#7E7E7E]// clock configuration[/color]
        #if SAMPLE_RATE == 88
          [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0xbc);
        #elif SAMPLE_RATE == 44
          [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0xa0);
        #elif SAMPLE_RATE == 22
          [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0xe0);
        #elif SAMPLE_RATE == 8
          [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0xac);
        #elif SAMPLE_RATE == 2
          [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0xce);
        #endif
        [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
      
        [color=#CC6600]Wire[/color].[color=#CC6600]beginTransmission[/color](0x1a);
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x12); [color=#7E7E7E]// codec enable[/color]
        [color=#CC6600]Wire[/color].[color=#CC6600]write[/color](0x01);
        [color=#CC6600]Wire[/color].[color=#CC6600]endTransmission[/color]();
        
}

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color](){
  
        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);
        AudioCodec_init();
        startTimer(TC1, 0, TC3_IRQn, 44100); [color=#7E7E7E]
}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color](){
}

Sorry for the extention of the post, I don't know what to do now, the only think I can do is check the interfaces with an oscilloscope, I have access to oscilloscopes at work so I think this week I should try it. Did anyone try any of this libraries with the Due? Help, please smiley-sad
4  Products / Arduino Due / Re: Arduino Due and 6DOF Accel/Gyro on: April 30, 2013, 08:45:28 am
Bump...     smiley-grin
Can anyone try this code, and see if you are faceing same problem.

Thx
MrLudvig

Well I am also trying to make this Wire library work. According to the DUE main page and a fast look at the source code, it seems that for the DUE they have adapted the library so it SHOULD be working. I tried to get a feedback from the library but the only thing I can do is reading the result of Wire.write() that returns the number of bytes written and it always returns '1' (that seems to be ok, but my board isn't working).

I have to say my problem is a little bit complex, I want to use the WM8731 audio codec, and this codec use two serial interfaces, one for the configuration of the chip (I2C that works with the Wire library) and the other for the data transmission (SPI). So I don't know if my problem is with the Wire library or with the SPI library... or both  smiley-sad

I suspect that the problem has something to do with the I2C or SPI speed, I have also checked the source code but it's a little hard to me to get some information from there. So at my job I have access to oscilloscopes and my next step is to check the protocols with the oscilloscope. I think I should do that this week, so as soon as I get some information I will reply.
Pages: [1]