Author Topic: PIC32MX, WM8731 I2C problem  (Read 4802 times)

0 Members and 1 Guest are viewing this topic.

Offline WozTopic starter

  • Newbie
  • Posts: 1
PIC32MX, WM8731 I2C problem
« on: February 12, 2014, 11:34:44 pm »
Hi!

I'm trying to play audio through a Wolfson WM8731 codec using a PIC32MX450F256L but I can't seem to get the I2C serial control interface to work.

The WM8731 is using 7-bit register addresses and 9 control data bits per register.

I'm trying to do the following:

 - Send device address + r/w bit (0x34).
 - When acknowledged, send 16-bits of data, 8-bit at a time (MSB first). B15-B8 is the register address + B8 of the data I want to write. And then send the remaining B7-B0 of data.

The codec acknowledges the device address but it wont acknowledge the last byte of control data.

I've added the code and a screenshot of what shows up in my logic analyzer. The code is based on a Microchip example. (Obviously it's the "codec_writeRegister"-function I can't seem to get correct.)


I hope someone can help me with this, I've spent a looot of time on this.

Thanks!
 

Offline rfbroadband

  • Supporter
  • ****
  • Posts: 186
  • Country: us
Re: PIC32MX, WM8731 I2C problem
« Reply #1 on: February 16, 2014, 03:56:46 am »
simplify your your problem first
- initialize I2C module
- set baud rate register for desired speed of I2C
(make sure peripheral divider reduces pclock to a freq. so the BRG register can configure the I2C clock speed.
- I assume you know, that queuing of events is not allowed with the PIC I2C modules!
That means, for example : if you write the slave address into the transmit register you need to check whether the register has been cleared before you send the next command! You can do this with interrupts or if you can 'waste' some clock cycles you constantly check the status register with

while(I2CxSTATbits.TRSTAT != 0);

I did not see anything in your code that indicates you made sure the registers were cleared before you sent the next command. I just found a few for loops and NOPs which I am sure will not work.

I would suggest you carefully study the I2C Programming guide for the PIC32s, it contains every thing one usually needs....

good luck

 

Offline johnwill

  • Contributor
  • Posts: 10
  • Country: us
Re: PIC32MX, WM8731 I2C problem
« Reply #2 on: March 15, 2014, 09:47:14 pm »
Hello, I also have problems with the I2C library. I have used the PICkit 2 as Logic analyzer, and see the clock instead of going at 100 kHz, goes at about 8 kHz (attached picture).

Try to change all the values of I2C1BRG in the /PINGUINO/pinguinoX.2rev305/p32/include/pinguino/core/i2c.c file, but still the same problem.

Thank you for some help!

I am using:
PIC32_Pinguino_OTG board
Ubuntu 10.10
Pinguino x.2 rev 305
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf