科大讯飞语音芯片xfs5152CE,分享遇到的一些坑

2022-10-17,,,

首先 芯片手册的i2c地址是写地址,是8位的,真正的地址是7位地址,应该是0x40,最低位是读写位,读置1,为0x81,写置0,为0x80.

如果是模拟i2c倒无所谓,最坑的是我用的是寄存器,所以必须要用7位地址才可以,这个地方坑了我好几天。

其次,在用uart串口的是时候,每次上电芯片会返回一个状态值0x4a,但i2c是不会主动返回的,需要你去读取

我是在写入语音之后接着读取状态字节

上电第一次写入数据并读取,会得到0x4a,之后的再读取都是0x41,0x4f

程序部分

我用的是msp430f5438a,i2c3

1 void i2c3_start(unsigned char address)
2 {
3   ucb3i2csa = address;
4   while(ucb3ctl1 & uctxstp);
5   ucb3ctl1 |= (uctr + uctxstt);
6   while(!(ucb3ifg & uctxifg));
7   ucb3ifg &= ~uctxifg;
8 }
1 void i2c3_writebyte(unsigned char data)
2 {
3   ucb3txbuf =data;
4   while(!(ucb3ifg & uctxifg));
5   ucb3ifg &= ~uctxifg;
6 }
1 void i2c3_writenbyte(unsigned char* data,int len)
2 {
3   for(int i=0;i<len;i++)
4   {
5     i2c3_writebyte(*data++);
6   }
7 }
 1 void i2c3_readnbyte(unsigned char *data,unsigned char len)
 2 {
 3   ucb3ctl1 &= ~uctr;
 4   ucb3ctl1 |= uctxstt;
 5   for(int i=0;i<len;i++)
 6   {
 7     while(!(ucb3ifg & ucrxifg));
 8     ucb3ifg &= ~ucrxifg;
 9     if(i==len-1)ucb3ctl1 |= uctxstp;
10     *data++ = ucb3rxbuf;
11   }
12 }
1 int xfs_set(unsigned char* cmd,int len,unsigned char *data,int n)
2 {
3   i2c3_start(0x40);
4   i2c3_writenbyte(cmd,len);
5   i2c3_readnbyte(data,n);
6   return 0;
7 }

 

未完待续

 

以上为原创,请勿转载

 

《科大讯飞语音芯片xfs5152CE,分享遇到的一些坑.doc》

下载本文的Word格式文档,以方便收藏与打印。