|
|
View previous topic :: View next topic |
Author |
Message |
Nick Araujo
Joined: 09 Nov 2023 Posts: 6
|
SPI PIC18F26Q43 Problem RC522 |
Posted: Thu Nov 09, 2023 5:02 am |
|
|
Hello everybody.
I have a problem making communication between the PIC18F26Q43 and a Mifare card reader RC522 board work. I have been using hardware for this purpose for many years, with several microcontroller options that have worked very well, such as 16F1827, 16F886, 16F1936, 16F15355, 18F25K22, always with the same routines and same communication libraries with the RC522.
But now I needed to use the PIC18F26Q43 because I need more memory for my application. But Mifare card reading is not done. I normally use the #use spi(FORCE_HW, MASTER, BITS=8, SPI1, MODE=0 ) directive together with #pin_select SDI1=PIN_C4
#pin_select SDO1=PIN_C5
#pin_select SCK1OUT=PIN_C3.
I checked with the oscilloscope and apparently all the signals are present (CS, CLK, MISO and MOSI), that is, the RC522 board is apparently responding to something, but the PIC doesn't understand it.
I've already tried several other settings in #use spi, such as changing the baudrate, etc. It works normally with other PICs on the same board, from 100KHz to 2Mhz, but not on the 18F26Q43.
I have already tried to do the configuration manually through the SPI-related registers, without success, the results are the same, that is, the signals are present, but the card is not read.
Is there anything different in the SPI from this PIC? Any new tricks I need to discover? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9255 Location: Greensville,Ontario
|
|
Posted: Thu Nov 09, 2023 6:35 am |
|
|
random thoughts as coffee's not quite ready..
OK, my first guess is 5 volt PIC and 3V RC522 module but you say that it's worked with other PICs....
.hmm.. new PIC has PPS pins, perhaps the 'logic levels' aren't the same has dedicated pins of the older PICs ?
I haven't used a PPS based PIC, others here sure have, hopefully they'll reply. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
Posted: Thu Nov 09, 2023 6:45 am |
|
|
Look at the sticky about #PIN_SELECT.
Look at how the _clock_ is setup.
On some of the PIC's the clock input is a distinct path from the clock
output. You are setting up the output (so the clock gets generated), but
not then feeding the clock into the input shift register. Result, data does
not get clocked in!....
Not sure if this is your problem, but I have seen this on a lot of the newer
chips....
Last edited by Ttelmah on Thu Nov 09, 2023 7:43 am; edited 1 time in total |
|
|
Nick Araujo
Joined: 09 Nov 2023 Posts: 6
|
|
Posted: Thu Nov 09, 2023 7:24 am |
|
|
temtronic wrote: | random thoughts as coffee's not quite ready..
OK, my first guess is 5 volt PIC and 3V RC522 module but you say that it's worked with other PICs....
.hmm.. new PIC has PPS pins, perhaps the 'logic levels' aren't the same has dedicated pins of the older PICs ?
I haven't used a PPS based PIC, others here sure have, hopefully they'll reply. |
Hi Temtronic, tks for your quick answer.
Yes, I have used the same pins that older version that don't have PPS. In new PICs, default position is the same. |
|
|
Nick Araujo
Joined: 09 Nov 2023 Posts: 6
|
|
Posted: Thu Nov 09, 2023 7:37 am |
|
|
Ttelmah wrote: | Look at the sticky about #PIN_SELECT.
Look at how the _clock_ is setup.
On some of the PIC's the clock input is a distinct path from the clock
output. You are setting up the output (so the clock gets generated), but
not then feeding the clock into the input shift register. Result, data does
not get clocked in!....
Not sure if this is your problem, but I have seen this on a lot of the never
chips.... |
Hi Ttelmah, tks for your answer.
I will try it and return with result more late.
But I have discovered somethig interesting: I have changed PIC 18F26Q43 for 18F25K42, for some tests and comparations. The same C code work fine at CCS 5.091, but don't work at 5.101 version... No changes were made on code, just compilling it on each version.
Why?? |
|
|
Nick Araujo
Joined: 09 Nov 2023 Posts: 6
|
|
Posted: Thu Nov 09, 2023 7:50 am |
|
|
I have changed PPS declarations for include clock in, like below, but don't work yet.
#pin_select SDI1=PIN_C4
#pin_select SDO1=PIN_C5
#pin_select SCK1OUT=PIN_C3
#pin_select SCK1IN=PIN_C3
On 5.115 version don't work too, just work on 5.091.
The problem is 5.091 don't suport PIC18F26Q43, just 5.101 and above, and I need to use this PIC for this project. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
Posted: Thu Nov 09, 2023 7:52 am |
|
|
101?....
Now there were issues with that version. A couple of oddities on bit handling
and registers on a few chips. I have motes here from my own work, that
I had to step back to a previous version to get existing code to work. This
was fixed a couple of versions latter.
I think it was an update in 5.100, allowing SPI to be used in one direction,
that caused an issue with the SPI library.
You may have hit one of those problems. |
|
|
Nick Araujo
Joined: 09 Nov 2023 Posts: 6
|
|
Posted: Thu Nov 09, 2023 8:01 am |
|
|
Ttelmah wrote: | 101?....
Now there were issues with that version. A couple of oddities on bit handling
and registers on a few chips. I have motes here from my own work, that
I had to step back to a previous version to get existing code to work. This
was fixed a couple of versions latter.
I think it was an update in 5.100, allowing SPI to be used in one direction,
that caused an issue with the SPI library.
You may have hit one of those problems. |
Tks Ttelmah, I also think this is the problem. Is there any solution for this? Since PIC18F26Q43 is not supported by 5.091, I will need to use 5.101 or 5.115. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
Posted: Thu Nov 09, 2023 8:25 am |
|
|
Contact CCS.
If you have a demonstrable problem, they will either do an updated library
or let you have an updated version, even if your subscription has expired. |
|
|
Nick Araujo
Joined: 09 Nov 2023 Posts: 6
|
|
Posted: Fri Nov 10, 2023 1:20 pm |
|
|
Ttelmah wrote: | Contact CCS.
If you have a demonstrable problem, they will either do an updated library
or let you have an updated version, even if your subscription has expired. |
I have contacted CCS Support. They tell me that:
**********************
I reviewed the spi_write() and spi_read() functions in the latest compiler versions and I believe the problem you're having is with the spi_read() function when a value is passed to it to clock out. In that case it not correctly waiting for the transfer to be complete before returning. I'm working correcting the issue. You can work around the problem in two ways:
1. Replace your call to spi_read() with the following:
SPI_Write(0);
value = SPI_Read();
The above will do what the call to value = SPI_Read(0); was suppose to do.
2. Replace your calls to spi_write() and spi_read() with spi_xfer().
********************************
I have tested this 2 option, and both was positive result.
I have tested the firmware for PIC18F25K42 and PIC18F26Q43, working fine!
Dear Tthelmah, this problem was SOLVED!
I hope this can help other users.
Thank you very much! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
|
|
|
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
|