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 support@ccsinfo.com

W5500 Library
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Tue Jul 21, 2020 10:56 pm     Reply with quote

In my applications related to i2c, it was not a problem if the integrated 3.3V and microcontroller was 5V. Here, I supply power to PIC with switchmode regulator (5v) and w5500 with ams1117 (3.3v).
Secondly, we are already trying to make a simple communication with the above code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Wed Jul 22, 2020 1:36 am     Reply with quote

It would only work if you use software I2C, on a port that has TTL input
buffers. The PIC standard I2C _hardware_ requires the signals to go up to
0.8*Vdd (so 4v).
temtronic



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

View user's profile Send private message

PostPosted: Wed Jul 22, 2020 4:35 am     Reply with quote

If memory serves me right, SPI input is a ST type, so it needs 80% of VDD to be a legal '1'. At 5v, that'd be 4 volts.

You say that it is working so perhaps the module has logic level conversion ? If not then you're just very lucky.
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Wed Jul 22, 2020 6:34 am     Reply with quote

Yes.
On paper, this cannot work.

The 5500, has '5v tolerant' inputs, so will accept the clock and data
from the PIC, but the MISO line from this chip back to the PIC will
not go even remotely close to the level needed for the PIC to receive
correctly.
The 5500 specifies it's Voh as minimum 2.4v, and it's maximum has
to be the supply voltage to the chip (so 3.3v). The Vih required by the
SPI input on the PIC is specified to require 4v.

However, as happens a lot of the time we have no real details of the
module actually involved. It may be that he has a 5500 module that
does have signal buffering. Though a lot don't (since chips like the
Arduino accept 2.4v as a 'high'), a few do. For example, the Wiznet
shield has optional buffering on the SPI signals for exactly this reason.
The IoREF signal powers the buffer. So if this or a similar module
is being used, and 5v is being fed to this signal, then all would be fine...
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Sat Jul 25, 2020 4:47 am     Reply with quote

Hello.
I keep trying.
First, I tried spi between two pic18f46k22. It worked fine when I sent and received a single data. However, when I sent two data at the same time, the data received by the Master was not correct. However, outgoing data was correct. Can we have the same problem here? Does writing successively with the XFER command cause problems when reading data?

Code:

/**********************************************

My connection with the w5500 may also be incorrect
PIC18f46k22             WIZNET IO (w5500)
           +5V ----->    +5V
           GND ----->    GND
_pinCLK pin_C3 ----->    SCK   
_pinSDI pin_C4 ----->    MISO    maybe pullup 4k7/does not change
_pinSDO pin_C5 ----->    MOSI    maybe pullup 4k7/does not change
_pinSCS pin_D0 ----->    CS
MCLR    pin_E3 ----->    RST
           GND ----->    INT   ??? I am Not sure this connect/does not change

**********************************************/
#include <18F46k22.h>
#device ADC=12
#fuses NOWDT,NOBROWNOUT,PUT,NOWRT,NODEBUG,INTRC_IO, NOMCLR, NOPROTECT, NOWDT, NOLVP,PLLEN                 
                 
#use delay(internal=64000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define _pinCLK  pin_C3
#define _pinSDI  pin_C4
#define _pinSDO  pin_C5
#define _pinSCS  pin_D0

#define BLOCK(x) (x<<3)
#define READ 0
#define VDMN 0


#use SPI(MASTER, DO=_pinSDO, DI = _pinSDI, CLK=_pinCLK,/*Enable=_pinSCS,*/ baud=1000000, bits=16, MODE=0, stream=AS5045)
unsigned int16 val;

Void as5045_write(){
   
   output_low(_pinSCS);
   spi_xfer(AS5045,0x0003,16);
   spi_xfer(AS5045, BLOCK(0x1D) | READ | VDMN ,8);
   val=spi_xfer(AS5045,0x0,8);
   output_high(_pinSCS);
   
   printf("val: %x\n",val);
}

void main()
{
   setup_oscillator(OSC_64MHZ , OSC_PLL_ON);
   output_high(_pinSCS);
   
   while(true)
   {
       if (input(pin_b4))
       {
         as5045_write();
     
         while(input(pin_b4));
     
       }
     
    }

  }

Finally, I noticed something like this.
When I write 0x1C or 0x1A instead of 0x1D, I am reading a value.
0x1D : 00
0x1C : 46 or 56
0x1B : 25 or 35
0x1A : 4e or ...

how that happens?

best regards or Smile
temtronic



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

View user's profile Send private message

PostPosted: Sat Jul 25, 2020 5:00 am     Reply with quote

Please post make/model of the W5500 module you're using.
It's critical we KNOW what the hardware is. 'W5500' is a 3 volt chip be I alsways assume posters are using 'modules' as SMD is really, really tiny to solder !
Also, to make life easy on you, change PIC VDD to 3 volts (same as W5500 REQUIRES). That PIC will run fine on 3 volts.
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Sat Jul 25, 2020 10:38 am     Reply with quote

The 0x1D read, reads the socket 7 register. Do you want to do this?.
The 0x1C read, reads a reserved register.
The 0x1B read, read the socket 6 RX buffer.
Not at all surprising that they give different results....
What is in these will depend on how _you_ program the chip, and
what is going on with the connected hardware.
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Sat Jul 25, 2020 8:55 pm     Reply with quote

temtronic wrote:
Please post make/model of the W5500 module you're using.
It's critical we KNOW what the hardware is. 'W5500' is a 3 volt chip be I alsways assume posters are using 'modules' as SMD is really, really tiny to solder !
Also, to make life easy on you, change PIC VDD to 3 volts (same as W5500 REQUIRES). That PIC will run fine on 3 volts.


I use WIZNET 850 io
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Sat Jul 25, 2020 11:43 pm     Reply with quote

Well, if you pull the circuit diagram for that, you can see it does not have
any buffering on the data lines. As such it is not compatible with the PIC
running at 5v.
As Jay says, run your PIC at 3.3v. You need to either do this, or add
buffering.
temtronic



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

View user's profile Send private message

PostPosted: Sun Jul 26, 2020 4:23 am     Reply with quote

I looked at the device... as I suspected it's a 3 volt peripheral.
The easy, simple solution is to run the PIC from the same 3 volt supply as the Wiznet device. Be sure it's rated for at least 1 amp ! According to the spec posted on Wiki... it'll draw 128ma. Without having a device to test, I don't know if that's steady state or pulsed so 1 Amp is the minimum I would use.
Also be sure all Vdd and Vss pins are connected and have a few bypass caps !

One reason I chose the PIC18F46K22 years ago was the fact it WILL run at full 64 MHz speed on either 5 or 3 volts. No need to order the 'L' version. ONE PIC does it all !

Jay
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Mon Jul 27, 2020 7:11 am     Reply with quote

I tried: 5V
I tried: 3.3v
I'm tired. Wink
But I still haven't seen the value of 0x17.
Could we have missed a little detail in the software?
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Mon Jul 27, 2020 7:29 am     Reply with quote

You won't get 0x17, till the connection is established. Means everything has
to actually be configured and working......

It's not a value you can test for until you have actually set up the chip,
and have got the connection being made.
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Tue Jul 28, 2020 5:48 am     Reply with quote

Ttelmah wrote:


Code:

#define BLOCK(x) (x<<3)
#define WRITE 4
#define READ 0
#define VDMN 0
#define FDL1 1
#define FDL2 2
#define FDL4 3

void main()
{
   int8 data_in;
   setup_adc_ports(NO_ANALOGS, VSS_VDD);
   output_high(CS); //ensure CS starts high
 
   while(TRUE)
   {
      output_low(CS); //You have this missing - essential
      spi_xfer(W5500, 0x0003,16);
     [b] spi_xfer(W5500, BLOCK(0x1D) | READ | VDMN ,8); [/b]
      data_in = spi_xfer(W5500, 0x0,8);
      output_high(CS); //same comment...
      printf("Dat: %x\n",data_in); //honestly easier to look at in hex     
   }
}

Let's clarify something

What was the reason for not showing: spi_xfer(W5500, BLOCK(0x1D) | READ | VDMN ,8); expression as spi_xfer(W5500,0xE8 ,8); ???

GAR (Gateway IP Address Register) [R/W] [0x0001 – 0x0004] [0x00]

I mean, is the expression above (0x00) the expression that should be shifted three bits to the left? Or can I write this way:
spi_xfer(W5500,0x00 ,8);
Ttelmah



Joined: 11 Mar 2010
Posts: 19224

View user's profile Send private message

PostPosted: Tue Jul 28, 2020 6:10 am     Reply with quote

The point is that the numbers for the block access are given in the data
sheet as the values that need to be shifted. If you do this 'yourself' all the
time, it has two big problems:
1) Anyone looking at the data sheet has to re-calculate each time to see
what value is involved.
2) You risk making a mistake.
Using the Macro to convert the 'data sheet' number, means you can just look
and see directly what block is involved. Also avoids making any errors
in this conversion. Costs nothing, since the macro is solved at compile
time.

The GAR, would require:
spi_xfer(W5500, BLOCK(0) | READ | VDMN ,8);

with the address as 1 to 3.

If you use address 1, you can perform a 4 byte read to read all four
registers.
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Tue Jul 28, 2020 7:54 am     Reply with quote

Thank you Ttelmah.
I will try.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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