View previous topic :: View next topic |
Author |
Message |
Mario_KA
Joined: 16 Nov 2017 Posts: 22
|
|
Posted: Sun Nov 26, 2017 1:08 pm |
|
|
I had that before and then I decided to use it without functions because I just want to read that one Register to find out where the issue is.
I still changed it and there is no difference :(
Quote: | #include <main.h>
#include <lcd16216.c>
#define VersionReg 0x37
#define CS PIN_A5
//spi modes
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
char buffer[17],text[17];
byte version;
int8 MFRC522_read(int8 addr)
{
int8 retval;
output_low(CS);
spi_write(((addr << 1) & 0x7E) | 0x80);
retval = spi_read(0x00);
output_high(CS);
return(retval);
}
void main()
{
// setup_oscillator(OSC_8MHZ, 3); //Adjust Oscillator for proper Serial Communication
setup_spi(SPI_MASTER|SPI_MODE_3|SPI_CLK_DIV_16);
lcd_init();
lcd_clear();
output_high(CS);
while(TRUE)
{
version = MFRC522_read(VersionReg);
if(!version)
{
lcd_clear();
text = "not found";
lcd_gotoxy(1, 1);//go to position 1,1 on lcd
lcd_print(text);
}
if(version)
{
lcd_clear();
text = "Module found";
lcd_gotoxy(1, 1);//go to position 1,1 on lcd
lcd_print(text);//print on lcd
sprintf(buffer,"%2X",(version)); //display version in hexadecimal
lcd_gotoxy(1, 2); //go to second line of lcd
lcd_print(buffer);
}
delay_ms(500);
}
} |
What do you think about the Voltage difference of MISO? Why has Arduino 3.3 and PIC16 0.1? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sun Nov 26, 2017 1:26 pm |
|
|
Quote: |
Sounds reasonable but didnt change anything unfortunately
|
It should change one thing. Your SPI bus clock line should now be sitting high.
You complained it was sitting low.
If it isn't sitting high, then you have a hardware problem. With this selected, when the bus is idle, the line sits driven high. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 26, 2017 1:36 pm |
|
|
Quote: | What do you think about the Voltage difference of MISO? Why has
Arduino 3.3 and PIC16 0.1? |
I suspect the connections between the microcontroller and the MFRC522
are different.
Post a list of the connections between the PIC and the MFRC522.
If you can, post a link to a photo of your board, so we can visually
check the connections.
Do a Google search for an image hosting website. Upload your photo
to the website. Then post a link to it here.
Quote: | free image hosting sites for forums |
Here is one:
https://postimages.org/
Read this section in their FAQ: https://postimages.org/faq
Quote: | How can I post images to a forum that doesn't use your plugin? |
|
|
|
Mario_KA
Joined: 16 Nov 2017 Posts: 22
|
|
Posted: Sun Nov 26, 2017 2:21 pm |
|
|
I swapped SDO and SDI several time just to make sure thats not the issue. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 26, 2017 2:36 pm |
|
|
Your diagram shows SDO on the PIC going to the 4th pin down on the
MFRC522 board, which is MISO. This is wrong. You have two output pins
driving each other. In other words, your diagram shows MISO and MOSI are
swapped and are incorrect.
You should:
1. Connect SDO to MOSI.
2. Connect SDI to MISO. |
|
|
Mario_KA
Joined: 16 Nov 2017 Posts: 22
|
|
Posted: Sun Nov 26, 2017 3:47 pm |
|
|
Yes true, but I swapped them without success.
It so weird because I just hooked up my MC3202-C ADC with SPI and it is running without any problem. So basically SPI seems correct from my point of view.
That's so weird because it runs with Arduino with a similar code...
I guess I have to wait till Tuesday because then I can check the in/outputs with an oscilloscope.
EDIT: It is working!!!! I had one VDD(PIN 11) still connected to 5 Volt -.-.
I removed the cable and it was working.
Thanks for your help!! |
|
|
Mario_KA
Joined: 16 Nov 2017 Posts: 22
|
|
Posted: Mon Nov 27, 2017 7:46 am |
|
|
This chip is giving me the hardest headache ever.
I can read/write but whenever I set the TxControlReg the chip turns off, even the LED on the chip is off and I have to reconnect.
I use the same Data as on Arduino
writeToRegister(TxControlReg, 0x83);
maybe someone can have a look on Page 50 https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 27, 2017 8:34 am |
|
|
Quote: | Whenever I set the TxControlReg the chip turns off.
writeToRegister(TxControlReg, 0x83); |
You are enabling the TX1 and TX2 pin drivers. What do you have
connected to those pins ?
According to the MFRC522 data sheet, when you enable TX1 and TX2,
the current consumption will increase by 60-100 ma. This increase may
overwhelm your power supply. The resulting voltage droop may cause
the MFRC522 and/or the PIC to reset. What are you using for a power supply ? |
|
|
Mario_KA
Joined: 16 Nov 2017 Posts: 22
|
|
Posted: Mon Nov 27, 2017 8:40 am |
|
|
I think Tx1 and TX2 are connected to the antenna , at least that what the library says.
I use the ICD- U40 as power supply and then an easy voltage divider made of two resistors to cut the voltage down to 3.3V. |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Mon Nov 27, 2017 9:40 am |
|
|
Are you using a resistor divider to try and function as a voltage regulator? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 27, 2017 9:59 am |
|
|
Mario_KA wrote: |
I use the ICD- U40 as power supply and then an easy voltage divider
made of two resistors to cut the voltage down to 3.3V.
|
What are those resistor values ? |
|
|
Mario_KA
Joined: 16 Nov 2017 Posts: 22
|
|
Posted: Mon Nov 27, 2017 12:27 pm |
|
|
gaugeguy wrote: | Are you using a resistor divider to try and function as a voltage regulator? |
Yes I thought that be sufficient for the first tests.
Quote: | What are those resistor values ? |
1Kohm and 2KOhm |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 27, 2017 12:47 pm |
|
|
Well, the MFRC522 data sheet says the current can go up to 100ma
when the TX outputs are enabled. So the effective load resistance
can be calculated:
R = V/I = 3.3v / 0.1 A = 33 ohms
So your power supply circuit then looks like this:
Code: |
+5v
|
|
\
/ 1K
\
/
|
|---------
| |
\ \
/ 2K / 33
\ \
/ /
| |
| |
----- -----
--- ---
- -
|
The equivalent resistance of 2K and 33 in parallel is:
Code: |
2K x 33
--------- = 32 ohms
2K + 33 |
So now, your voltage divider is 1K on the top and 32 on the bottom.
With 5v on the top, that gives 0.15v output.
That explains why everything stops when you turn on the Tx inputs.
You need to get a real 3.3v voltage regulator, and with appropriate
capacitors on input and output. |
|
|
Mario_KA
Joined: 16 Nov 2017 Posts: 22
|
|
Posted: Mon Nov 27, 2017 1:06 pm |
|
|
PCM programmer wrote: | Well, the MFRC522 data sheet says the current can go up to 100ma
when the TX outputs are enabled. So the effective load resistance
can be calculated:
R = V/I = 3.3v / 0.1 A = 33 ohms
So your power supply circuit then looks like this:
The equivalent resistance of 2K and 33 in parallel is:
Code: |
2K x 33
--------- = 32 ohms
2K + 33 |
So now, your voltage divider is 1K on the top and 32 on the bottom.
With 5v on the top, that gives 0.15v output.
That explains why everything stops when you turn on the Tx inputs.
You need to get a real 3.3v voltage regulator, and with appropriate
capacitors on input and output. |
Alrighty hooked up my lm317-t and its not shutting down anymore. But I dont have capacitors for now. Just 100µF.
Lets see where this ends tonight ^^
EDIT: I highly appreciate your help guys. It is working perfectly fine now.
I am so grateful |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed Nov 29, 2017 4:56 pm |
|
|
You should post your working program in the 'code library' here. I'm sure many, like myself, would appreciate seeing the code. It'll be a good 'starter' or 'reference' to use. |
|
|
|