CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

TDA7314 audio processor i2c help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Secersh



Joined: 19 Oct 2009
Posts: 8
Location: Serbia, Belgrade

View user's profile Send private message

TDA7314 audio processor i2c help
PostPosted: Sun Dec 26, 2010 5:56 am     Reply with quote

Hi, i used TDA7314 and PIC16F876a width encoder and 4*20 char LCD as volume/tone control for my amp, and am having trouble width TDA(http://www.datasheetcatalog.org/datasheet/stmicroelectronics/1487.pdf), i think that the problem is i2c, here is the code...thanks in advance...

Code:
#include "C:\Documents and Settings\Cersik\My Documents\Amp\Amp.h"

#define LCD_ENABLE_PIN PIN_B0
#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#include <lcd420.c>
#use I2C(master,slow,sda=PIN_C4,scl=PIN_C3)

signed value1=30;
signed value2=7;
signed value3=7;
int newencoder;
int lastencoder;
signed vol=-63;
signed bastre[15]={-14,-12,-10,-8,-6,-4,-2,0,2,4,6,8,10,12,14};
int bas[15]={96,97,98,99,100,101,102,103,110,109,108,107,106,105,104};
int tre[15]={112,113,114,115,116,117,118,119,126,125,124,123,122,121,120};
int sel=0;
int pos1=8;
int i;

void lcd_load_custom_chars(void);

void main()
{
   lcd_init();
   lcd_load_custom_chars();
   printf(lcd_putc "\f\n      Welcome\003");
   delay_ms(2000);

   while(1){

      printf(lcd_putc "\f");
      lcd_gotoxy(1,1);
      for(i=0;i<20;i++){
      lcd_putc(0);}
      printf(lcd_putc "\n Volume        %ddb",vol);
      printf(lcd_putc "\n Bass          %ddb",bastre[value2]);
      printf(lcd_putc "\n Treble        %ddb",bastre[value3]);
      delay_ms(150);
    if(input(pin_c5)==0){
       sel++;
       if(sel>2)
       sel=0;}
    if(sel==0){
       lcd_gotoxy(1,2);
       lcd_putc(2);
       lcd_gotoxy(1,1);
       pos1=(63-value1)/3;
       if(pos1>19)
       pos1=20;
       for(i=0;i<pos1;i++){
       lcd_putc(1);}
             newencoder = (input_c() & 0b00000110);
      if(newencoder != lastencoder){
      if (bit_test(newencoder,2) == bit_test(lastencoder,1))
         value1++; else value1--;
         lastencoder = newencoder;
      delay_ms(25);}
       if(value1<0)
       value1=0;
       if(value1>63)
       value1=63;
       vol=-(value1);
       }
    if(sel==1){
       lcd_gotoxy(1,3);
       lcd_putc(2);
       pos1=value2+3;
       lcd_gotoxy(pos1,1);
       lcd_putc(1);
       lcd_putc(1);
             newencoder = (input_c() & 0b00000110);
      if(newencoder != lastencoder){
      if (bit_test(newencoder,2) == bit_test(lastencoder,1))
         value2++; else value2--;
         lastencoder = newencoder;
      delay_ms(25);}
       if(value2<0)
       value2=0;
       if(value2>14)
       value2=14;
       }
    if(sel==2){
       lcd_gotoxy(1,4);
       lcd_putc(2);
       pos1=value3+3;
       lcd_gotoxy(pos1,1);
       lcd_putc(1);
       lcd_putc(1);
                    newencoder = (input_c() & 0b00000110);
      if(newencoder != lastencoder){
      if (bit_test(newencoder,2) == bit_test(lastencoder,1))
         value3++; else value3--;
         lastencoder = newencoder;
      delay_ms(25);}
       if(value3<0)
       value3=0;
       if(value3>14)
       value3=14;
       }
       delay_ms(500);
       i2c_start();
       i2c_write(0x88);
       i2c_write(value1);
       i2c_write(bas[value2]);
       i2c_write(tre[value3]);
       i2c_stop();
       delay_ms(10);}
}

const int8 lcd_custom_chars[] ={159,128,128,128,128,128,128,159,159,128,159,159,159,159,128,159,132,134,133,133,132,132,156,156,131,141,139,141,137,139,155,152};

void lcd_load_custom_chars(void)
{
int8 i;

// Set address counter pointing to CGRAM address 0.
lcd_send_byte(0, 0x40);

// Load custom lcd character data into CGRAM.
// It can only hold a maximum of 8 custom characters.
for(i = 0; i < sizeof(lcd_custom_chars); i++)
   {
    lcd_send_byte(1, lcd_custom_chars[i]);
   }

// Set address counter pointing back to the DDRAM.
lcd_send_byte(0, 0x80);
}
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 26, 2010 6:16 am     Reply with quote

hardware ?
do you have the correct pullup resistors on the I2C bus?

do you have the device on the correct pins(and not reversed !)?

software ?
you seem to have a lot of IF statements 'in a row'
Any chance you're skipping over the I2C code section due to a wrongly construced IF -Else section ? I try to indent every nested IF... to better show the 'flow' of the code.

Have you tried a small I2C function just to write and read the I2C device without the encoder code?
Secersh



Joined: 19 Oct 2009
Posts: 8
Location: Serbia, Belgrade

View user's profile Send private message

PostPosted: Sun Dec 26, 2010 6:26 am     Reply with quote

Solved it, i just wrote all 8 data bytes instead of 3 to the TDA...thanks for reply...
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 26, 2010 7:07 am     Reply with quote

Yup, I read the data sheet and while it doesn't SAY that all 8 bytes have to be sent....the 'data train' of start...address..data...stop bits would INDICATE that all 8 need to be sent..

So you'll have to send all 8 bytes, even though you might just want to increase the bass.

Happy you got it to work,looks like a nice project !
Secersh



Joined: 19 Oct 2009
Posts: 8
Location: Serbia, Belgrade

View user's profile Send private message

PostPosted: Sun Dec 26, 2010 8:29 am     Reply with quote

I hope it will be done by tomorrow, maybe some pics... Laughing
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Wed May 18, 2011 2:49 am     Reply with quote

can you post your corrected code ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group