The "Kern" (core) is always in the middle, be it of something two- or three-dimensional. As the "Sonnenblumenkern" is in the middle surrounded by flower leaves, it is a "Kern", like the "Atomkern" which is in the center of the atom. A "Korn" (grain) is a tiny, usually spheric item of homogenous nature, e.g. das Samenkorn, das Sandkorn, das Staubkorn, das Maiskorn, das Weizenkorn. As "Weizenkorn" is an extremely important example for a natural "Korn", "Korn" is used synonymously for wheat in general.
However, there is some scheme in using "Körner" or "Kerne" when it comes to what we eat or feed, as "Kerne" usually originate from fruit, nuts, and flowers – it is the nature of those plants to keep their seeds always somewhere in the center –, whereas "Körner" usually originate from cereals like wheat, corn, rice, etc. which openly present their seeds as very strictly arranged and regular portions. That's how you can distinguish those terms on a practical level.