Problem using ADC and SPI

Create new topics, add your comment, remark, bugs...
graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Problem using ADC and SPI

Postby graele » Fri Feb 06, 2009 1:35 pm

Hello!

I've a strange problem using the ADC and the SPI.
In particular, I'm trying to realize a controller using the dsPIC33FJ128GP802.

I've no problems using just the ADC. I receive the signal, and I can use it without
problem. But, if I try to communicate through the SPI1 port with a MCP4821 (DA converter),
the ADC stop working (or that's what it seems...), and anyway, the SPI doesn't work neither...

I set the pin mapping so that I use the ports RP10 and RP11 for the SDO and SDCKO respectively.
Then I set the SPI in Master mode, configuring the frequency rate to 2 MHz (I'm using a cristal of
20 MHz and working with 40 MIPS).

The misfunction of the SPI is that it doesn't generate any clock on the SDCKO pin, and so also the
trasmission of data doesn't work. Contemporary, also the ADC stop working...

Can you help me please? That's really important and urgent for me to solve..

Thank you in advance!

Manu

graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Re: Problem using ADC and SPI

Postby graele » Fri Feb 06, 2009 1:41 pm

ah...i forgot to say (if it can be useful) that even if the ADC stop working, the dsPIC is still working generally
(because I can make a LED blinking without problems...)

Manu

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: Problem using ADC and SPI

Postby LubinKerhuel » Fri Feb 06, 2009 1:44 pm

Hi Manu,

I did not used yet theses chip with port mapping function on projects, thus there may be buggy.

Could you please upload your model on the forum ? That would help for testing.
Also, you may have a look on the C code generated by the real time workshop (configure your model to generate the html C report). If you find something strange in a peripheral configuration, let me know...

Lubin

graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Re: Problem using ADC and SPI

Postby graele » Fri Feb 06, 2009 2:28 pm

Well, i don't have a remote space to upload the model.
Eventually, if you want, I can send it to you by email.

I already checked the PIN mapping set in the C code generated.. and looking at the data sheet of the dsPIC
it's seems like if there are no errors... I really don't understand why it works that way!

Even because it's not such a complex schema... and I really need to make it working soon, 'cause my prof
at the uni wants a demonstration of this controller for tuersday...

Thank you for the attention received..

Manu

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: Problem using ADC and SPI

Postby LubinKerhuel » Fri Feb 06, 2009 3:03 pm

You can upload directly on the forum (look tab 'upload attachement' at the bottom when writting a message) or even by mail.

I may have a look during the week-end and but I can't promise to find the problem by tuesday... even more if it is not obvious ;-)

Lubin

graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Re: Problem using ADC and SPI

Postby graele » Fri Feb 06, 2009 3:10 pm

Ok, thank you very much!

I've added the file as you've indicated...

Just a quick question... is the TRISB register the one dedicated to specify if a pin of the PORTB is used
as input or as output? Because probably the mistake can be in the setting of the TRISB register...

Manu
Attachments
prova.mdl
(39.27 KiB) Downloaded 263 times

graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Re: Problem using ADC and SPI

Postby graele » Fri Feb 06, 2009 3:23 pm

No, everything's fine with the TRISB register.. I'm sorry...

Manu

graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Re: Problem using ADC and SPI

Postby graele » Sat Feb 07, 2009 12:41 pm

It keeps not working...

I read each single instruction of the code, and everything seems perfect.

In my trial, I just open the SPI1 port, after having mapped it on particular pins, in master mode...
Then, using the oscilloscope, I read the pin designated for the SCK1OUT, but no clock there!

What do I do wrong? Shall I expect a clock on that pin or not?

I've also tried with new dsPIC, thinking the one I'm using can be broken, but all the dsPIC I've tried
gives the same problem...

Any idea?

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: Problem using ADC and SPI

Postby LubinKerhuel » Sat Feb 07, 2009 1:11 pm

There is thus no relationhsip with ADC ?

you confirm that SPI alone is not working ?
In the Port mapping, try to map all pin of the SPI1 peripheral (with clock In = Clock-Out ; RP11 on your model ; and map also Data Input)
Did you check generated code for port mapping ?
SPI code shoud work as I am using it in many proects (see example page on the wiki).

Use the htlm C report (Simulaion==>Configuration Parameters ==> Real-Time Workshop ==> Create code generation report ...
It may helps.

Make sure that the constant you send is set to a sampling time to .001. (that's Ok on the model you posted)

You could set-up a MPLAB project and import C code generated by matlab for debugging.

I will test out when I get times (I need to cable the 33F128GP802 I have)

Lubin

graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Re: Problem using ADC and SPI

Postby graele » Sat Feb 07, 2009 3:30 pm

Well...

I've mapped the peripheral as you suggested, making the clock in and clock out coincident.
But nothing...

Then I've looked at the generated code, and I've noticed that it makes the peripheral mapping
after enabling the SPI... while, I think, it should be the opposite.. so I changed the order, and
I recompiled using the MPLAB... but it doesn't work...

I just enabled the SPI, without sending data this time, expecting to have the clock anyway.. but
nothing, it just doesn't work...

And yes, it seems that the ADC works fine, while the SPI no...
So, now I'm just focusing on the SPI...

Any idea??

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: Problem using ADC and SPI

Postby LubinKerhuel » Sat Feb 07, 2009 3:46 pm

Hi manu,

SPI (MASTER) generates clock signal only while sending data. No clock otherwise.

I tested Peripheral mapping on this chip with the Rx-Tx UART block. As it works, It should be the same for every mapped peripheral.

Thus, I have no idea. You should perhaps try to make SPI work starting a new MPLAB project. if you make it, compares your code with the matlab generated one. If you can't make it, check if there is no errata for this chip, and check the microchip forum.

graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Re: Problem using ADC and SPI

Postby graele » Sat Feb 07, 2009 4:33 pm

I've implemented the whole circuit, and also the sending of data.. But still nothings..
I checked for the errata, but about the SPI there's nothing relevant...

Does your SPI connection of your dsPIC work fine? Or did you just try the UART connection??

Please, let me know, and still thank you for the help!

Manu

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: Problem using ADC and SPI

Postby LubinKerhuel » Sun Feb 08, 2009 2:37 pm

Hi Manu,

It's likely I will not get time to do testing today... anywat, SPI has been tested on project on 30f chip. (for example in IMU) but wasn't used yet (at least by myself) on project with 33f chip.
Few changes between spi on 33F and 30f appears on the SPIxCON register, but bits that changes are not used so they should not change anything.

You could use MPLAB debugger and check the config register (SPIxCON1, SPIxCON2 and SPIxSTAT) to see if something's wrong with them. If something's wrong, it may be a problem on the C code generated or in the microchip definition of theses register address (check compiler definition files).

Let me know if you find something

Lubin

graele
Posts: 10
Joined: Fri Feb 06, 2009 11:04 am

Re: Problem using ADC and SPI

Postby graele » Sun Feb 08, 2009 5:56 pm

Hi Lubin...

I'm posting something on the Microchip forum, as you've suggested.. as soon as I'll solve the SPI problem
I'll write you what was wrong.. 'cause actually the code seems to be fine, and also the electric connections..

By the way... do you have some code examples and electronic schema (PCB...) that you personally implemented
and that you know it works? So, probably, giving a look, I can understand where it's the mistake..

In fact, it's quite difficult to find complete examples (like electronic schema and c-code) together..

Thanks for your help!

Manu

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: Problem using ADC and SPI

Postby LubinKerhuel » Sun Feb 08, 2009 6:21 pm

The IMU page I provide has schematic for the electronics parts.

But for testing purpose, you could just test the SPI output and clock output. They should works, even when not connected to any another system. In this way, SPI bus is much more easier to debug than I2C (I2C does not work when nothing's connected on the other side)

Thanks to repport if you find anything or if it finally works !

Lubin

malife
Expert
Posts: 56
Joined: Tue Apr 17, 2007 7:24 am
Location: Santa Cruz, CA
Contact:

Re: Problem using ADC and SPI

Postby malife » Wed Feb 11, 2009 8:09 pm

Hello All,
From what I read seems that your SPI is an error mode. If you get an overwrite error, your dsPIC will continue working normally but your SPI engine will freeze until you aknowledge the error and clear the error flag. It is a good idea enable the SPI error interrupt and handle the interrupt accordingly in an ISR. Make sure you read the 33F family reference manual to see how to go about it.

Hope this helps.


Return to “General Remark and Questions”

Who is online

Users browsing this forum: No registered users and 1 guest